Disable dialog for host to accept connection in WiFiP2PManager - java

I'm just looking at the WiFiP2PManager in Android. It appears that if I host a service and a user connects, then the host has to approve the connection. However, I do not want this as in my application the host will acknowledge this when they start hosting.
Is there anyway to do that, and if I can't do that in anyway at all, is there a way of telling the system that the user tapped 'Yes'?
Thanks

There is currently no way to do this though from Android 4.2.2 it is possible to remember previous groups.
Look at this issue(it deals with this exact problem):https://code.google.com/p/android/issues/detail?id=30880

Related

Android: have app send request to another app over network (on other phone)

I have two apps: "app" and "receiver", the latter of which also runs as a service on the phone. These are designed to be run on two separate phones - only one receiver will ever exist, which will be on my phone.
I'll try to make the problem as simple as I can: from the app, I'd like to be able to press a button saying 'hello', which would then load up an activity on the receiver's phone (from the service) also saying 'hello'. Pretty much I just don't know how to get the two devices to talk to each other. This will only be used over the same Wi-Fi connection. Would a broadcast be a suitable way to do this?
I've just started Android development a few days ago so I'm not sure how to do it - it's probably simple - and any help will be massively appreciated!
Many thanks!
Would a broadcast be a suitable way to do this?
No. Broadcasts can be used for inter-app communication, not inter-device communication.
Instead, devices on the same LAN can adress each other using their local IPs (usually 192.168.x.x).
One option would be to open a socket connection, see how to create Socket connection in Android?

Android/Smack: Keep XMPP connection alive in sleep mode

I have an Android application that has a chat client as one of its features. The chat client uses XMPP based on the Smack library for Android and running Openfire as XMPP server in the background. The connection is established using BOSH The whole XMPP connection handling is implemented as a service to run and listen in the background for incoming messages even if not activity of the app is in the foreground. So far, everything works perfectly fine.
The only problem seems to be the sleep mode. In the emulator (when set to "Stay Awake") or with the phone in use, the XMPP connections is holding and the app can send and receive messages. However, once the phone goes into sleep mode, the XMPP connection breaks down -- I can see it in the Admin Console of the Openfire server that the user is offline. Intuitively, I want to receive messages all the time like, e.g., WhatsApp.
Of course, I've searched online including Stackoverflow, but I couldn't get a definitive answer. Often the use case seems to be that a task has to be performed periodically, say, once every hour. But this doesn't seem to fir in case of a chat client. Since I assume this is a common use case -- after all, there a so many chat apps or apps with chat features out there -- these are my question:
How to I have to change / extend the app that I can receive chat message while the phone is sleeping?
I've stumbled upon WakeLock. Is this the way to go or are these not suitable for my use case?
Since Lollipop, there's also the JobScheduler API which itself uses WakeLock. Any better?
How does, for example, WhatsApp handles this case?
On a side note: I have problems with the sleep mode using the emulator for debugging. When I switch off "Stay Awake" in the emulator, the screen goes black after 1+ min and the XMPP connection breaks. But I somehow have no idea how to wake up / switch the emulator back on once it went black. Android Studio actually tells me at some point that the device or something is gone, and I have to restart the emulator again.
The exact way to resolve this issue is by using push notification.
It is the natural behavior of XMPP connection to get disconnected after the specified idle interval i.e when the device goes to sleep.
Coming to the case of WhatsApp, it also uses the same XMPP and maintains a server which acts as a wrapper class on the messages exchanged. This server checks the message status whether it is delivered or not. If not delivered, it sends a push notification, now at the device end in the push service when a message is received, it checks if the connection is active and is authenticated or not.
If not authenticated, it re-establishes the connection. In this way, the most chat apps manage this timeout exception.
Hope this helps :)
You don't need push notifications, you don't need WakeLocks. Instead simply
Whitelist your app from doze mode
Use a sticky (START_STICKY) background service
Use Smack's ServerPingWithAlarmManager
Act on CONNECTIVY_CHANGED intents send by Android, and use XMPPTCPConnection's instantShutdown() in that case.

Android Networking Exception: Connection reset by peer

I have an Android application where I connect frequently to a web service that I control using SSL exclusively. The first thing a user does that results in network activity is login and I currently use the Ion library for this although I tend to think my issue is not specific to Ion. This works as expected except for one specific user that has limited all internet access on the Android device to only work with my web service. They have done this by using their router to create a firewall that blocks all traffic except the specified domains. When this firewall is turned on they can't login via the app because of the following error:
java.net.SocketException
recvfrom failed: ECONNRESET (Connection reset by peer)
They can use the browser to go to my website and access the same web service with the firewall turned on and everything works fine. In addition, they can turn the firewall off, login successfully (i.e. successfully initial the first connection), turn it back on and subsequent network connections continue to work. The user can even log off and log back in without issue. It continues to work with the filter on until they quit the app. When they then restart the app and try to login the error returns. This seems like very odd behavior and I'm not entirely sure it is an ion issue but I'm not sure what to do. Does anyone have any ideas on what could be causing this issue?
UPDATE:
Per a comment, I tested my application with Volley. It does appear that Volley works with the filter turned on. I would prefer to stick with Ion though due to some of its other feature so if anyone has any ideas on how to make Ion work in this scenario I would greatly appreciate the help.

GCM - Detect Device Prescence

Is there a way to notify the server when a device connects and disconnects from the GCM platform?
Connection can be implemented easily enough at the application level since I would be able to send a message to my server via CCS. Detecting when the device is offline does not appear to be so simple.
I was hoping that there was a control message I could tap into to detect this?
thenIn these types of scenarios's, the pinging methodology is the best. For example if your client suddenly looses all his batterypower and the phone suddenly dies. The client will therefore not be able to send a request to your server that he is no longer online. Simultaneously, on the server-side, he is still flagged as "online".
The pinging mechanism reduces this problem by proposing a solution such that "If a ping is not received in a timely manner then flag the user as offline".
The Openfire plugin at the server side is one of the best one available till now that does this job for you. You can give it a shot.
Hope that Helps!!
There is the roster flag which indicates this:
connectionConfiguration.setRosterLoadedAtLogin(true);

Java App on Mac asking for allow network connections everytime

My Java.app broadcasts a packet on the network as soon as it starts up. Everytime I start this app, the Mac asks me do I want to allow network connections blah..blah.. Can I use info.plist or something to allow network access to this app and not bother the user who has trustingly downloaded and installed my app.
Thanks
You can choose to allow incoming connections for specific services in System Preferences > Security > Firewall.
Addendum: You application will appear only if the user has chosen to "Set access for specific services and applications." It will be added the first time the application attempts to open the port.
Addendum: The application appears with the name java in the Firewall pane. Once the user chooses to accept or deny, the dialog ceases to appear. This simple example is convenient for testing.
If you codesign your app (using the same key across updates) it should work properly with the app-specific firewall on. It seems to be a bug on Apple's side that unsigned java apps are prompted for allowing network connections (even if they don't try to listen to the network) every time they are run.

Categories