How to detect if Android wear switched the connection from bluetooth to wifi or vice versa? And is there a way to force it to connect via bluetooth?
Being an Android framework, you can register a broadcast receiver to be notified when connectivity status changes. In general, when your watch is connected to a phone directly (which only happens via BT), wifi connection is dropped and when it is not connected, if your phone is wifi capable and if a wifi network is available, it gets connected to the cloud node. In that case, you cannot force it to connect through BT since, most likely, it is not possible (might be due to distance or many other reasons). What exactly are you trying to accomplish?
Related
I am working in an application that requires an Android device to connect to a Wi-Fi network. This Wi-Fi network does not have internet access - it is a Wi-Fi network created by a end-device and used only to communicate with it using TCP sockets. I would like to be able to access the cellular data internet connection on the Android device WHILE communicating with this device over Wi-Fi and I wanted to know if this is possible.
Here is what I know so far:
It is possible to get list of all interfaces available on the device and their corresponding IP addresses via the Android NetworkInterface API.
There is an option in the Developer Settings in Android to keep cellular data interface up even when Wi-Fi is connected.
It is possible to provide the local address for the Socket to bind to when creating a Socket()
With these in mind:
When I am connected to the Wi-Fi network with the SIM card in the device and LTE enabled I am able to get wlan0 interface with a "local" IP address in the format 192.168.x.x and rmnet0 interface with a non-local IP address.
However, depending on the device, I am only ever able to access ONE of them at a time.
For example, on a Pixel 2 XL running Oreo 8.1, LTE Enabled, Cellular Data Always On enabled:
I am unable to communicate over Wi-Fi AT ALL. Any Sockets created with the Wi-Fi local address time out.
On a Galaxy Tab S2 SM-T818W running Nougat 7.1, LTE Enabled, Cellular Data Always On enabled:
I am able to communicate over Wi-Fi but not able access the cellular data interface.
The only way I am able to access the wlan0 interface on the Pixel 2 XL is by calling requestNetwork from Android's ConnectivityManager API and requesting Network with TRANSPORT_WIFI capabilities but this defeats the purpose since now all communication and sockets will be bound only to the Wi-Fi network.
I know that when USB tethering is enabled, it is possible to access devices on the Virtual USB "Ethernet Network" interface which shows up as eth0 with either the wlan0 interface or even the rmnet0 interface by specifying local addresses on the Socket connection calls. It just appears to be a problem with Wi-Fi and cellular data.
I wanted to know if this is an inherent and intended Android limitation or is there a way to access both interfaces at the same time that I am missing.
Appreciate your help. Please let me know if it would be better for me to provide specific code snippets, I wasn't sure since it would make this post quite long.
Best,
I am developing an app in which the first thing i need is how to get devices that are connected to my wifi network or same wifi network .ie ip adress,device name etc.
I don't have any idea how to do that have searched alot but there are no examples available.
I have done one thing that i will ping 255 ips and whichever will respond will be the connected ips but the problem here is that there are virtual ips already assigned to some websites so i need to detect only the real device ip addresses.
I want to do the same thing as done in the app WifiTalkie
Follow Any one of the following:
Way1:
If you mean you want to see all the devices connected to your current WiFi connection (and you are not trying to do Ad Hoc networking), then you are essentially wanting to run a network scanner.
There are a bunch of these around. This one has the source available on github
http://rorist.github.com/android-network-discovery/
Way2:
Refer How to detect all the Devices connected in a WiFi network from Android App
The Problem:
The bluetooth connection between the android app(GATT client) and two TI boards(CC2640R2F, GATT server) is unstable. When the android app connects to the two boards, the bluetooth connection state of the two boards toggle rapidly between connected and disconnected states. As a result the service discovery process is affected and sometimes there are no GATT characteristics discovered(The GATT service is just empty). The problem occurs with only android devices running marshmallow(6.0+) and above.
This issue also occurs on other third-party apps available in the play store such as BLE scanner, sensorTag and nrf connect running on those android devices.
Fixes attempted on Android side:
The following fixes were attempted on the Android side but these were unsuccessful.
a time delay(tried upto 2000ms) was set between connection successful event and gatt.discoverServices() request.
Have separate device.gattConnect(...) methods for devices below and above marshmallow(6.0). Devices above marshmallow require a TRANSPORT parameter.
Switch connection between the GATT servers to ensure that only one server is connected at a given time.
Created separate Gatt callbacks for the two servers and separate threads for all the operations that took place involving the two servers.
The only fix that was successful is connecting only one server to the client. To connect another server, the app needs to be reopened. If another device is connected at the same time, the issue still occurs.
Data Collected:
The bluetooth sniffer logs were collected from the android side and are attached.
The 'btsnoop_hci_success.log' file deals with the successful BLE connection between an android device(Samsung galaxy s7 edge) running marshmallow(6.0.1) and just one server(a purifier).
The 'btsnoop_hci_fail.log' file deals with the problematic BLE connection between the same android device and two servers(a sensor and a purifier).
this is Dharmesh i developed one application of gps. my gps connected via Bluetooth but my program take too much time identify comport. but if i connected my gps with usb cable it run easily any one face this issue and how to overcome this issue.
thanking you......
This may be a side effect of the fact that you let the bluetooth port go between attempts. Bluetooth connections setup and teardown are very expensive, so if you connect to the GPS, you should remain connected. Of course, that doesn't help during dev, so once you know the bluetooth connection works, it probably makes sense to use the USB cable except when testing the connection for regressions.
Sorry for kind of a dummy question, but I'm wondering how to work with WiFi connection via android. My application needs to transfer some data (both receiving and sending) with PC or with other android device using WiFi. How should I organize the process? I mean, how should I establish connection, then should I open a socket for data transfering, etc. Is there any way to do it without internet connection, smth like bluetooth, except wifi.p2p (which is only available for android 4.0)? Would be grateful for as detailed manual as possible.
Every network connection even if only in the local network or localhost reqieres the INTERNET permission.
Bluetooth and NFC might be an option, but I have no experiance with that.