To grab MAC address first we have to enable device WIFI, after enabling it we can get the MAC address.
public static String macAddress(final Context context){
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
String address;
if(wifiManager.isWifiEnabled()) {
// WIFI ALREADY ENABLED. GRAB THE MAC ADDRESS HERE
WifiInfo info = wifiManager.getConnectionInfo();
address = info.getMacAddress();
} else {
// ENABLE THE WIFI FIRST
wifiManager.setWifiEnabled(true);
// WIFI IS NOW ENABLED. GRAB THE MAC ADDRESS HERE
WifiInfo info = wifiManager.getConnectionInfo();
address = info.getMacAddress();
}
return address;
}
To know your device IMEI number, first generating device id from TelephonyManager class
public static String getIMEI(final Context context) {
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String imei_number = tm.getDeviceId();
return imei_number;
}
//add permission in your manifest file
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Android Unique ID
public static String getuniqueId(final Context context) {
String androidId;
androidId = System.getString(this.getContentResolver(),Settings.Secure.ANDROID_ID);
return androidId;
}
0 Comment(s)