android.permission.READ_PHONE_STATE权限被拒绝

时间:2015-09-23 12:48:10

标签: java android

我收到一个例外情况,告诉我使用getDeviceId()拒绝使用权限,但我的清单中有android.permission.READ_PHONE_STATE

这是例外:

getDeviceId: Neither user 10055 nor current process has android.permission.READ_PHONE_STATE.

这是显而易见的:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="client.test.me.client" >
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  <uses-permission android:name="android.permission.CALL_PHONE"/>
  <uses-permission android:name="android.permission.SEND_SMS"/>


  <application
   android:allowBackup="true"
   android:icon="@mipmap/ic_launcher"
   android:label="@string/app_name"
   android:theme="@style/AppTheme">
     <activity
      android:name=".HiddenActivity"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Translucent.NoTitleBar">
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
      </activity>
      <receiver android:name=".BootReceiver">
        <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED" />
          <category android:name="android.intent.category.HOME" />
        </intent-filter>
      </receiver>

      <service android:name="client.test.me.client.ClientService" >
        <intent-filter>
          <action android:name=".ClientService" />
        </intent-filter>
      </service>
  </application>
</manifest>

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "client.test.me.client"
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
}

获取deviceId的代码:

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

byte[] idBytes = tm.getDeviceId().getBytes();

编辑:这不重复我找不到与他有同样问题的问题。

1 个答案:

答案 0 :(得分:0)

试试这个,

TelephonyManager TM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // IMEI No.
    String imeiNo = TM.getDeviceId();

    // IMSI No.
    String imsiNo = TM.getSubscriberId();

    // SIM Serial No.
    String simSerialNo  = TM.getSimSerialNumber();

    // Android Unique ID
    String androidId = System.getString(this.getContentResolver(),Settings.Secure.ANDROID_ID);

不要忘记添加

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

到您的清单文件。