ali mazaheri
ali mazaheri

Reputation: 217

MAC address in android phone

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();
    } 

Upvotes: 1

Views: 86

Answers (2)

Haniyeh Ehsaninejad
Haniyeh Ehsaninejad

Reputation: 119

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(); 

Upvotes: 3

Sahjad Ansari
Sahjad Ansari

Reputation: 110

I have solved this problem by using this

    private String deviceId() {
    return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}

Upvotes: -1

Related Questions