MAC address of bluetooth or wifi of an android device - android

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

Related

Android WifiManager disconnect from a WifiSpot but never connects automatically again

I am using this code to disconnect from a Wifispot:
if(getActivity()!=null) {
WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
wifiManager.disconnect();
}
WiFi disconnects and Settings show Wifi On, the wifi I was connected is shown as
Saved, secured with WPA/WPA2
That's perfect. The problem is that I get out of range and return into the range again of the WiFi, it doesn't "reconnect" automatically. Which code should I add to automatically reconnects WiFis disconnected by WifiManager?
When you set up your wifi configuration.
add this :
mWifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
for more information http://developer.android.com/intl/es/reference/android/net/wifi/WifiConfiguration.html
Hope this help!

Transmitting small amounts of information using WiFi SSIDs?

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.

How can I learn SSID of that I am connected to wifi point?

I want to learn the connected wif-fi point SSID. By doing so, I will not try to connect to the same point. How can I learn SSID of that I am connected to wifi point ? Is there a method like isConnected() ?
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.d("wifiInfo", wifiInfo.toString());
Log.d("SSID",wifiInfo.getSSID());
you will need the android.permission.ACCESS_WIFI_STATE in your manifest
There is one problem:
I selected wifi "XYZ" whoz pwd was unknwn. Entered some random pwd.
It shows authentication problem. on wifi screen.
But, Log.d("SSID",wifiInfo.getSSID());
Results into "XYZ"

Android: How to determine which Wi-Fi network is connected

I know how to determine if a wi-fi connection is the active connection. However, can someone tell how to determine which wi-fi network is the current active?
Use WifiManager.getConnectionInfo(). This returns a WifiInfo object which contains all the info you need about the active wifi connection; in particular, WifiInfo.getSSID() will give you the SSID.
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
String BSSID=wifiManager.getConnectionInfo().getBSSID();

I want to change MAC address of android device?

I am getting MAC address of devices using wifi interface:
WifiManager wifiMan = (WifiManager) this.getSystemService(
Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
String macAddr = wifiInf.getMacAddress();
Is there any way for retrieve mac address without wifi interface?
Also confirm me Can we able to change MAc address of android devices?
Please confirm me android framework support these things or not?
A MAC address uniquely identifies a network adapter (e.g. WiFi or Bluetooth), so you'll have to access that adapter to retrieve it's MAC address. To get the MAC address of a bluetooth adapter you can use:
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter != null) {
String mac = btAdapter.getAddress();
}
Note that this code requires the android.permission.BLUETOOTH permission and that your code to get the WiFi adapter's MAC requires the android.permission.ACCESS_WIFI_STATE permission. Also, both codes may not work when the adapter is turned off.
There is this post on MAC spoofing (returning a false MAC address) but spoofing can only be done on rooted phones. If you'll google you'll probably find more info on MAC spoofing.

Categories

Resources