I want to know Mobile number and Wi-Fi-Address .Howis this possible.Can anyone Help me
try this for Mobile Number
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();
but its not always reliable on for example non phone device. You will also need to add permision "android.permission.READ_PHONE_STATE".
for MAC address
WifiManager wfManager;
WifiInfo wifiinfo;
wfManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
wifiinfo = wfManager.getConnectionInfo();
String MAC = wifiinfo.getMacAddress();
public String getMAC() {
wifimanager= (WifiManager)getSystemService(Context.WIFI_SERVICE);
wifiinfo = wifimanager.getConnectionInfo();
MAC=wifiinfo.getMacAddress();
System.out.println("MAC address info---- "+MAC);
Toast.makeText(getApplicationContext(), "MAC address:"+MAC , Toast.LENGTH_LONG).show();
if(MAC==null){
MAC="1A:DC:5C:8E:15:7B";
}
return MAC;
}
Related
I build an android app with Android Studio with Java and I want to get the mac address from the phone
limit user any action do and somethings else
who can help me?
my code is this but didnt work
private void getmacadres() {
String macAddress =
android.provider.Settings.Secure.getString(this.getApplicationContext().getContentResolver(), "android_id");
Toast.makeText(G.Context, macAddress, Toast.LENGTH_LONG).show();
}
add this permission to your manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
and use this:
WifiManager wifiManager = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
I have solved this problem by using this
private String deviceId() {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
I have an Android application that works on a single phone. In order to work on a single device, I need to get the MAC address or Android ID. I decided to get the MAC address because the app needs to connect on a specified WiFi network.
How to get the MAC address from an Android device?
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();
String address = info.getMacAddress();
Currently I'm using this but it is not stable.
When the app restarts, it returns 02:00:00:00:00:00. and crashes.
//getting mac address from mobile
private String getMacAddr() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) continue;
byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
return "";
}
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
// res1.append(Integer.toHexString(b & 0xFF) + ":");
res1.append(String.format("%02X:",b));
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
//handle exception
}
return "";
}
Use these permission in manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Get this method's return value to a String variable and use it.
String MAC = getMacAddr();
Hope I helped
Try this code
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
Log.e(TAG,"MAC Address : " + macAddress);
Also, add below permission in your manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
and output is
MAC Address : 84:11:9E:B7:1E:D0
Using WifiManger, you will get MAC address
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String macAddress = wifiInfo.getMacAddress();
Don't forget to add wifi permission
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
use this for Android ID
private String deviceId() {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
I want to know is there any way to determine whatever I am logging should go through WIFI instead of device network,Is there any methods as part of Log entries SDK
Try this code for wifi connection or not.
private boolean checkConnectedToDesiredWifi() {
boolean connected = false;
WifiManager wifiManager =(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiManager.getConnectionInfo();
String desiredMacAddress = wifiInf.getMacAddress();
WifiInfo wifi = wifiManager.getConnectionInfo();
if (wifi != null) {
// get current router Mac address
String bssid = wifi.getBSSID();
connected = desiredMacAddress.equals(bssid);
}
return connected;
}
I need to determine if the Android device is connected to Wifi, and if so, obtain its Wifi IP address.
I know how to use ConnectivityManager to determine whether the active network is a Wifi network, and I know how to use java.net.NetworkInterface to iterate over the available network interfaces and get their IP addresses.
What I don't know how to do is determine which IP address belongs to the Wifi network, if there is more than one address found. Any advice?
Thanks.
public String getIpAddr() {
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipString = String.format(
"%d.%d.%d.%d",
(ip & 0xff),
(ip >> 8 & 0xff),
(ip >> 16 & 0xff),
(ip >> 24 & 0xff));
return ipString;
}
Please Note: You need to add android.permission.INTERNET and android.permission.ACCESS_WIFI_STATE in your AndroidManifest.xml as <user-permission/> to access the code.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Please try this code.
ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//To fetch the state of the Wi-Fi network in the device
Boolean isWifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
WifiManager wifiMgr = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
//To fetch the name of the Wi-Fi network to which the device is connected
String wifiName = wifiInfo.getSSID();
static final int IP_ADDRESS_LENGTH = 32;
public static Integer getSystemWifiIpAddress(Context context)
{
WifiManager wManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wManager.getConnectionInfo();
int ipAddress = wInfo.getIpAddress();
if (ipAddress == 0)
return null;
return ipAddress;
}
how to get macid and mobile number only in android mobile device not in database
try this
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = manager.getConnectionInfo();
String MACAddress = wifiInfo.getMacAddress();