0

I get an exception which tell me that permission is denied to use getDeviceId() but I have android.permission.READ_PHONE_STATE in my manifest.

Here is exception:

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

Here is manifest:

<?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'
}

Code to get deviceId:

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

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

Edit: This is not a duplicate I can not find a question where they have the same problem as me.

Emma22
  • 23
  • 1
  • 6

1 Answers1

0

Try this ,

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

Don't forget to add

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

to your manifest file.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
  • I am already doing all that. If you read my manifest you will see I already have that permission. – Emma22 Sep 23 '15 at 13:07
  • can you post your code of getDeviceId() and logcat – KishuDroid Sep 23 '15 at 13:08
  • Please, see http://stackoverflow.com/questions/32635704/cant-get-the-send-sms-permission as indicated above. Different symptom but the same problem. – headuck Sep 23 '15 at 13:28
  • @headuck that must be the problem I will test now. Does this mean my app won't run on android 6.0? – Emma22 Sep 23 '15 at 13:32
  • As per @headduck's link you need to use requestPermissions() method – KishuDroid Sep 23 '15 at 13:34
  • Read Mark's blog article. Just need to do something more, asking user for permission. Example code (for camera) https://github.com/googlesamples/android-RuntimePermissionsBasic/blob/master/Application/src/main/java/com/example/android/basicpermissions/MainActivity.java – headuck Sep 23 '15 at 13:35