

Android7.0でMACアドレスの取得方法を教えていただけないでしょうか。  
下記はMACアドレスを取得しようとしているコードです。

[code]

    String MacAddress = "";
    DevicePolicyManager dpm = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName cn = new ComponentName(context, AdminReceiver.class);
    if (dpm.isAdminActive(cn)) {
        MacAddress = dpm.getWifiMacAddress(cn);
        Log.d("","MacAddress:"+MacAddress);
    }else{
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "");
        context.startActivity(intent);
    }
    
[/code]

AdminReceiver.java

[code]

    public class AdminReceiver extends DeviceAdminReceiver {
        @Override
        public void onEnabled(Context context, Intent intent) {
            super.onEnabled(context, intent);
        }
    
        @Override
        public void onDisabled(Context context, Intent intent) {
            super.onDisabled(context, intent);
        }
    }
    
[/code]

admin.xml

[code]

    <?xml version="1.0" encoding="utf-8"?>
    
    <device-admin xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-policies>
            <limit-password />
            <watch-login />
            <reset-password />
            <force-lock />
            <wipe-data />
            <expire-password />
            <encrypted-storage />
            <disable-camera />
            <disable-keyguard-features />
        </uses-policies>
    </device-admin>
    
[/code]

AndroidManifest.xml

[code]

    <receiver
        android:name=".AdminReceiver"
        android:description="@string/admin_description"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/admin" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>
    
[/code]


CC BY-SA 3.0
2016-09-09T11:48:28.533
28784
2016-09-11T16:00:37.420
2016-09-11T16:00:37.420
8567
8567
question
android java
Android7.0 MACアドレスの取得