-1

This code worked my phone.But it didnt worked from my friend phone. I have permission too . I get This error ;

Neither user 10109 nor current process has android.permission.READ_PHONE_STATE.

Permission ;

    <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

This is my Code ;

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    IMEI= telephonyManager.getDeviceId();
Zarma Mokana
  • 71
  • 2
  • 10

2 Answers2

1

This is probably due to your friend running on Android 6.0 (API level 23). You need to add permissions at Runtime as well as the ones in the Manifest.

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.

Refer here for more information. Maybe take a look at this question to see how to implement runtime permissions, although it's explained in the first link as well.

Community
  • 1
  • 1
Vucko
  • 7,371
  • 2
  • 27
  • 45
1

As per new marshmallow os you need to configure runtime permission for "READ_SMS"

like this :

String permission = Manifest.permission.READ_SMS;

    if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(permission);

        if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)){
            requestPermissions(new String[]{permission}), SMS_PERMISSION);
        }
    }
Nilay Dani
  • 896
  • 6
  • 24
  • Can you give me this source code ? I cant see permissionList its Array ? Or ArrayList What is it ? – Zarma Mokana Jul 18 '16 at 16:36
  • Yes You can explore android developer's site , Here is a nice example https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en – Nilay Dani Jul 18 '16 at 16:37
  • yes , definitely but for above sdk version 23 only. – Nilay Dani Jul 18 '16 at 16:44
  • if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { return ; } This code is enought about it ? – Zarma Mokana Jul 18 '16 at 16:46