Android get bluetooth address in marshmallow - android

blutooth address and wifi address (mac) are depracted since android 6
marshmallow .
bluetooth.getAddress();
how we can get unique number from android device such as bluetooth address or wifi mac address ?

Access to the mac address has been deliberately removed:
http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
use this code :
get the mac address via reflection or Settings.Secure:
String macAddress = android.provider.Settings.Secure.getString(context.getContentResolver(), "bluetooth_address");

Related

How to get the host address when a device is the Group Owner(GO) on a WiFiDirect connection?

I am using WiFiDirect to connect my android device to another device using WiFiDirect.
I have the following method to get the host IP address which works great when device is not the group owner.
public String getDestinationDeviceIpAddress(WifiP2pInfo wifiP2pInfo) {
String destinationAddress;
if (wifiP2pInfo.isGroupOwner) {
destinationAddress = // How to get the address here ???
} else {
// This works great !
destinationAddress = wifiP2pInfo.groupOwnerAddress.getHostAddress();
}
return destinationAddress;
}
Question:
How do I get the peer's address for the case where wifiP2pInfo.isGroupOwner is true? In other words, how to get the peer's address when the android device is the Group Owner(GO)?
Android sdk version:
Targeting android sdk version 28 and above

How to scan specific Bluetooth device and get information from it in Android?

I try to build a project that can get Bluetooth rssi from specific devices. However, I'm stuck on that. Is there any way to filter and specify the scanning results and then continuously get information from the chosen Bluetooth devices?
Many thanks.
Yes
You can filter using device MAC address in android
//lets say i have a device i got by searching BT devices
BluetoothDevice device;
String mac = "00:11:22:AA:BB:CC"
if(mac.equals(device.getAddress)){
// my device found
}
public String getAddress ()
Added in API level 5
Returns the hardware address of this BluetoothDevice.
Bluetooth hardware address as string
for more see Android BluetoothDevice doc

How to get IP addresses of other Wifi enabled devices by programmatically on the same network?

In my Android mobile, I clicked from the phone and saw settings-> Wireless Controls->Wifi Settings and tapped on the network I have connected to. It popped up a Dialog with network status, level, speed, signal strength, IP address and security type. So just I got an IP address of network.
How can I get IP addresses of other wifi enabled devices by giving (known IP address got from my mobile) as a Input?
Actually to be clear, how to give specific known IP address as a Input and must be able to get other Unknown Ip addresses of Wifi enabled devices connected on the same network programmatically in Android 2.3 ?
For getting the IP Address you can check getIpAddress() in WifiInfo
Pseudo Code,
WifiManager mWifiManager = (WifiManager)
getSystemService(Context.WIFI_SERVICE);
WifiInfo mWifiInfo = mWifiManager.getConnectionInfo();
Log.e("IP in Mask Integer", mWifiInfo.getIpAddress()+"");
Log.e("IP Address", intToIP(mWifiInfo.getIpAddress())+"");
public String intToIP(int i) {
return (( i & 0xFF)+ "."+((i >> 8 ) & 0xFF)+
"."+((i >> 16 ) & 0xFF)+"."+((i >> 24 ) & 0xFF));
}
To find other devices in the same network you need to SCAN that network.
Scanning means to find the possible IPs in your subnet (using your IP address and subnet mask you can find the possible range and usually for home routers it is between x.x.x.1 ~ x.x.x.254) then iterate through these IPs and for each IP do PING or try to connect with TCP/UDP to some/all ports until you get a response which means there is an active device using that IP. However, it you get no response at all then it might be that there is no device using that IP or the device is filtering these requests (a firewall dropping your packages) or simply that device doesn't have any listening services.
To learn more about this check out some well known tools like nmap
WifiManager myWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo myWifiInfo = myWifiManager.getConnectionInfo();
int myIp = myWifiInfo.getIpAddress();
textWifiManager.setText(myWifiManager.toString());
textWifiInfo.setText(myWifiInfo.toString());
int intMyIp3 = myIp/0x1000000;
int intMyIp3mod = myIp%0x1000000;
int intMyIp2 = intMyIp3mod/0x10000;
int intMyIp2mod = intMyIp3mod%0x10000;
int intMyIp1 = intMyIp2mod/0x100;
int intMyIp0 = intMyIp2mod%0x100;
textVIewIp.setText(String.valueOf(intMyIp0)
+ "." + String.valueOf(intMyIp1)
+ "." + String.valueOf(intMyIp2)
+ "." + String.valueOf(intMyIp3)
);
Also have to modify AndroidManifest.xml to grant permission of android.permission.ACCESS_WIFI_STATE.
click settings, > wireless & networks > then wlan > click the options button on your phone (it should be beside your home button thingy) then click advanced :)

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.

get the MAC address of the closest WiFi using Android

Q/ Write an Android program to get the MAC address of the closest WiFi Access Point
is there any ready written program i can use ?
dose any body have information that might help me ?
thank you
See this:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults()
The BSSID is the MAC address of the AP.

Categories

Resources