Is it possible to allow 2 Android devices to communicate by using SSIDs? One device would broadcast a message by creating a hotspot with the message as its SSID. Nearby devices can read and interpret the message. I couldn't find anything in the Android documentation that allow this. Is it possible on Android devices and how would I do this?
You can use this call to create a hotspot:
private boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled);
...
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "\"SSID_NAME\"";
// more configs here.
And to scan wifis around something like:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> results = wifi.getScanResults();
You can read the wifi info from there. Maybe you can identify the hotspot by MAC address.
Related
I am developing and app for a restaurant. They want their customers to connect their Wifi via app.
The code:
WifiManager mManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration config = new WifiConfiguration();
//Asume I added things to config.
int id = mManager.addNetwork(config);
mManager.enableNetwork(id, true);
So even if I don't call
myManager.saveConfiguration();
can the device connect that Router without my app?
Thank you for your time.
OK! I read about it more and more, I found the answer. And also the solution.
So, you need to use use
mManager.removeNetwork(id);
after it is disconnected. I assume you saved your BSSID's in somewhere. Also save the ID that you got. With a Timer task working at background check the current BSSID, if it is not the same, remove the ID from Configured Networks as above.
Here is how you check current BSSID:
WifiInfo wifiInfo = mManager.getConnectionInfo();
String currentBSSID = wifiInfo.getBSSID();
I am working on an app that would allow indoor navigation using hardware devices that emit wifi signals in large public places such as hotels and hospitals. Each location would have multiple devices and each device would be unique so that we can identify the exact location of the device/person.
For this I don't want the user to connect to the wifi, if only a scan of the network was possible which could determine the current wifi beacon the mobile is closest to would do the job. I decided to use Android's WifiManager for the task:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
wifi.startScan() ;
List<ScanResult> mScanResults = wifi.getScanResults();
String s = "" ;
for(ScanResult result: mScanResults){
Log.d("Wifi", result.SSID) ;
}
None of the attributes for result seem to be appropriate for use as a UID for Wifi Beacon, I have two questions:
a) Can we use something like a BSSID for this purpose?
b) Can I write my own wifi manager class and then somehow negotiate a handshake with the wifi where it just tells me who it is without connecting? If so please share resources for doing the same.
I am trying to create a help wizard to recover from bad network connections in the app. One test case I hope to handle is the case where an end user has WiFi turned off, WiFi is available, and the mobile network is slower than the WiFi network. In this event, I want to be able to (1) discover the available WiFi network s, (2) find the WiFi network speed, (3) Compare its speed to the mobile network speed, (4) digest the user changes to the faster network.
For this to work, I need to know how to programmatically get information on available connections. Is that something we can do? If so, how can we tell what connections are available? Thanks in advance.
Task-1: Discover the available WiFi network
This can be done by getting WifiManager's instance from the System.
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getScanResults();
// The above is an async call and will results are available System will broadcast `SCAN_RESULTS_AVAILABLE` intent and you need to set a `BroadCastReceiver` for it.
// And get the results like this
List<ScanResult> results = wifiManager.getScanResults();
Task-2&3: find the network speed
This link gives an answer to your question about how to get network speeds of wifi and mobile network
Wifi:
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
In case of mobile it should work:
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();
Then You should compare this signal levels and if WIFI signal is better keep it turn on, but if mobile is better disconnect wifi
Task-4: Switching to the option with higher speed
In Android by default, if wifi is on and connected then your mobile network won't be used. Hence to use mobile data you must either disconnect from all available wifi-networks or switch off the wifi.
I will also suggest you to read link this, this and this for getting more information on how to get connection speed.
Company http://renewlondon.com/ have the terminal stations that collect all near by mac addresses
Can I via iOS SDK, and Android SDK,do the same thing?
You can access the wifi data using 'WifiManager' and after the scanning the scanresult contain all the data like
BSSID The address of the access point.
SSID The network name.
capabilities Describes the authentication, key management, and encryption schemes supported by the access point.
frequency The frequency in MHz of the channel over which the client is communicating with the access point.
level The detected signal level in dBm.
timestamp Time Synchronization Function (tsf) timestamp in microseconds when this result was last seen.
about the wifi devices.
if you need more related to coding, I think I can help you...
Sample code
WifiManager wManager;
List<ScanResult> wifiList;
wManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// Inside BroadcastReceiver()
wifiList = wManager.getScanResults();
for (int i=0; i<wifiList.size(); i++){
ScanResult scanresult = wifiList.get(i);
System.out.println("SSID: "+ssid);
System.out.println("RSSI: "+scanresult.level);
System.out.println("Frequency: "+scanresult.frequency);
System.out.println("BSSID: "+scanresult.BSSID);
System.out.println("Capability: "+scanresult.capabilities);
}
Also checkout the BroadcastReceiver().
One way i can think of doing this is making your device as wifi hotspot and use some hidden api to discover devices.You are basically trying to mimic an access point.
Otherwise each device would need some p2p framework on them-either wifi direct on or some other framework like alljoyn or samsung chord which helps in peer to peer discovery
I am writing a program about the communication between android device and PC.
Is there any way to get the MAC address of BLUETOOTH or WiFi of an android device, when the Bluetooth or WiFi is turned OFF?
If so, how?
this works for me with wifi on and off i not try the bluetooth
WifiManager wimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String address = wimanager.getConnectionInfo().getMacAddress();
Log.d("TOKEN", address);
Yes, you can get MAC addresses even when Bluetooth / WiFi is OFF.
Getting bluetooth information is as easy as this:
BluetoothAdapter.getDefaultAdapter().getAddress(); // MAC address
BluetoothAdapter.getDefaultAdapter().isEnabled(); // true if ON
No need to use Context, yay!
And to complete the answer.. WiFi state:
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getConnectionInfo().getMacAddress(); // MAC address
wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED; // true if ON