I wanna create an application using wifi direct.
In connecting step between 2 devices. I wanna set wifi direct on if wifi direct state of the device use my application is off. Can I change wifi direct state of the device(mobile)? How?
When i send request to connect to another devices Can my application auto accept the request without asking the device received request?
Please support me. Thanks so much!!!
The answer is yes, you can turn on/off the WIFI connection of the handset using the WifiManager:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
WIFI and wifidirect are enabled at the same time. You will need to add the needed permissions to the Android manifest.
Check Android Developers for more information on "http://developer.android.com/reference/android/net/wifi/WifiManager.html#setWifiEnabled(boolean)".
About accepting the connection without human interaction... It should be possible, but only if your app is the one handling the connection at the end-side and you have developed it in a way that will take care of all the steps. However this is not good from an end-user perspective since you are not giving him the power of decision. A nice solution would be doing it manually and allowing the user to decide if allow it automatically for the next time for that specific device.
Please, provide feedback if anything is not clear or does not really answers your questions.
Related
In my flutter app, I need to get information from a device via wifi as a stream. Also I need to keep my google maps online via Mobile internet. How can I use both wifi and mobile network at the same time in my phone. I made a lot of search but I can't find any solution for this.
I don't think it's possible.
The phone would need two network antennas and possibly two network adapters.
You can surely toggle both wifi and mobile data at the same time and they can probably switch frequently to optimize your connection or send requests to different services.
But you can't really use them both at the same time.
(if it's possible) I don't recommend it, since a majority of phones will not support this feature since you need two network antennas.
From the facts as presented, there are a couple of possible solutions, but they aren't perfect and I'm guessing on one as I haven't tested it yet.
One, Google Maps has an offline mode. You can set it up to download maps for offline use. It will show your position on the maps whether you are connected to the internet or not, but you won't get traffic data or accurate travel times. Not great, but it can work.
Two, it is possible for a phone to have a WiFi network and Cellular network active at the same time, but not in the way everyone seemed to think. Since you are wanting the cellular connection open to have access to the internet, I'm assuming this is because the WiFi network you want to access doesn't have the internet. So, reverse the WiFi network. Setup your phone to be a hotspot network, it runs its own WiFi network while maintaining access to the internet through its cellular network. I'm guessing here, but unless phones have some specific security protocol forbidding it I don't know about (which can be the case), your app should be able to contact anything connected to its phone's WiFi while still having access to the internet.
If this doesn't work for some reason, you can try a trick I used when I set up a car office. Get a mobile hotspot device. It's a device you can put a cellular SIMM in and it creates a WiFi hotspot. You can connect to it, along with other devices in the car. All will being using WiFi and the hotspot will provide the internet access.
If what you are connected to can only create a WiFi network for you to access and it can't be configured to connect to one itself, you could technically still be able to do it by network switching. Much harder to do (probably impossible on some devices) and will likely mess with other apps depending on internet access, so a real break glass in case of emergency type of situation there.
In IOS we have implemented using Reachability framework which provided by apple, In Android We need to find whether active internet connection is available are not. Actually We need find whether Wi-fi connected with active internet connection or not, We have tried lot of ways but we need to deduct instantly. In this case we should find out host reachability status of internet connection. We have tried this below link .
It was taken some time for the response, But we need to get instant response to finish the requirement. We need to solve the case, device connected with Wi-Fi but doesn't have internet connection. If anyone know the solution help us. Thanks in advance.
In Android, you can subscribe to get a notification when it WiFi has connected. This is as instant as you are going to get.
ConnectivityManager will also allow you to poll to see if WiFi is available, but it's much better (and more battery friendly) to get an event.
See here for details
I'm in the design phase of an Android application that will require a connection to multiple wifi networks, and I'm wondering if anyone can provide advice and/or code snippets regarding the best way to go about this. The app will have a connection to one wifi network that has internet access, and another wifi network with no internet access that will be used to share data accross the devices (raspberry pis) on it.
Can I be connected to both networks simultaneously? If so, how do I specify which network to use when making a request? I've been reading the Android 5.0 documentation which indicates its possible, but I'm a little confused on how to implement it.
If its not possible, this post from 2011 says that the WiFi Direct standard could be another solution. WiFi Direct is now supported on Android, but I can't find many examples of how to use it to achieve my goal.
Any advice is much appreciated!
As far as I know, you can have only one connection to the Access point, meaning that you can indeed make the device connected to the access point which offers you the internet connection, but then you can not connect to other networks.
Anyway, I would suppose that in your use case that is not the problem, actually I don't see any problems there. At least, if you simply have the connection and then have the Raspberry Pi's connected to you, i.e. you simply create a access point in your Android device, and all devices connect to it.
I know there are a lot of threads about GPS in Android, but I did not find an answer for this. Is it possible to track the position of another android device, and send some information between this two devices only with GPS (with no Internet connection)?
GPS is a one-way information channel from satellites to devices which want to know their own position. There is absolutely no way you can send information via GPS.
If you are looking for direct communication between android devices, your best options are Bluetooth and Wi-Fi Direct.
Sorry, it's simply impossible. No internet connection = no communication.
I'm starting to write an Android application to perform background monitoring of my web server. With WiFi enabled a problem will be that traffic is directed over that by default, I'd like to always use 3G for the HTTP request to check external availability as well. I know I could use this code to disable WiFi programmatically:
WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
But as it will be running in the background it's a bit clumsy and will interrupt other operations over WiFi while the check is in progress. Looking at the Socket Documentation I can't see any apparent way to achieve this. I'm wondering if there's any supported way to achieve this on a non-rooted phone? I have full control over the server so the protocol doesn't specifically have to be HTTP.
This seems like it would be an awfully dangerous feature for Android to allow.
What about users who are on metered 3G plans? How would they feel if an app forced them to use a 3G connection and then bugged out or something and blew away their whole data quota without them even knowing it (thinking they were on WiFi)?
Also, there could not be more than one active networks at a time.
Possible Resolutions-
What you can do is to force disable the wifi network, when your application is active and then enable it later.
Also, Try searching for a method called requestRouteToHost. It allows you to specify the network type and the host you want to find a route to.
I don't believe you can do this in android since only one network connection is active at any given time. A similar question is posted here as well:
Send HTTP request through 3G network without using WiFi?