android7.0關於TelephonyManager.getDeviceId()返回null的問題


在android7.0的系統下發現TelephonyManager.getDeviceId()在權限允許的情況下取得返回值也為null,解決方法如下:

 

public static String getDeviceId(Context context) {
    String id;
    //android.telephony.TelephonyManager
    TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null) {
        id = mTelephony.getDeviceId();
    } else {
        //android.provider.Settings;
        id = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
    }
    return id;
}
相關資料地址:http://stackoverflow.com/questions/3802644/will-telephonymanger-getdeviceid-return-device-id-for-tablets-like-galaxy-tab


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM