question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

android 11 android.permission.READ_PHONE_NUMBERS

See original GitHub issue

Description

I’ve been trying to solve this problem for 2 days this problem only happens on android 11

when I changed targetSDKversion from 29 to 30 my app works good for only first oppening when I give permissions my app crash and I’m getting this error

Screenshot_20211111-163833

LOGCAT ERRORS:

11-12 11:42:55.338 899 1105 E unknown:ReactNative: java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10205 nor current process has android.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at android.os.Parcel.createExceptionOrNull(Parcel.java:2373) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at android.os.Parcel.createException(Parcel.java:2357) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at android.os.Parcel.readException(Parcel.java:2340) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at android.os.Parcel.readException(Parcel.java:2282) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.android.internal.telephony.ITelephony$Stub$Proxy.getLine1NumberForDisplay(ITelephony.java:10831) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:4479) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at android.telephony.TelephonyManager.getLine1Number(TelephonyManager.java:4447) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.learnium.RNDeviceInfo.RNDeviceModule.generateConstants(RNDeviceModule.java:547) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.learnium.RNDeviceInfo.RNDeviceModule.<init>(RNDeviceModule.java:84) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.learnium.RNDeviceInfo.RNDeviceInfo.createNativeModules(RNDeviceInfo.java:28) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:41) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1212) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1182) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1120) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:123) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:943) 11-12 11:42:55.338 899 1105 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:923)

Manifest File: image

Version

0.59.9

Output of react-native info

React Native Environment Info: System: OS: Windows 10 CPU: (12) x64 Intel® Core™ i5-10500 CPU @ 3.10GHz
Memory: 2.74 GB / 15.83 GB Binaries: Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 4.1.0.0 AI-201.8743.12.41.7199119

Steps to reproduce

upgrade targetSDKversion from 29 to 30 add READ_PHONE_NUMBERS permissions for android 11

Snack, code example, screenshot, or link to a repository

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cortinicocommented, Nov 15, 2021

Android 11 introduced changes on the READ_PHONE_STATE permissions: https://developer.android.com/about/versions/11/privacy/permissions

The crash seems to be unrelated to react-native. Are you calling .requestPermission correctly? Could you provide a reproducer using an empty template?

1reaction
VishalChaturvedicommented, Nov 15, 2021

I have resolved my issue with the below changes

  1. Check and remove all react-native dependencies which required SMS permission (As i don’t need it in my project)
  2. Remove all commented code from AndriodManifest.xml and update permission to access phone number Before <uses-permission android:name="android.permission.READ_PHONE_STATE" /> After <uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="29" /> <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
  3. Update build.gradlle (Path: andriod/build.gradlle) buildscript { ext { googlePlayServicesVersion = "16.1.0" firebaseVersion = "17.3.4" buildToolsVersion = "30.0.2" minSdkVersion = 21 compileSdkVersion = 30 targetSdkVersion = 30 supportLibVersion = "28.0.0" }...
  4. In React Native’s Splash.js asking for permission await PermissionsAndroid.requestMultiple([ PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE, PermissionsAndroid.PERMISSIONS.READ_CALL_LOG, PermissionsAndroid.PERMISSIONS.READ_CONTACTS]);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Storage updates in Android 11
Starting in Android 11, apps cannot create their own app-specific directory on external storage. To access the directory that the system provides for...
Read more >
Change app permissions on your Android phone
Change permissions based on their type · On your phone, open the Settings app. · Tap Privacy And then Permission manager. · Tap...
Read more >
READ_PHONE_STATE permission seems to be actively ...
I manually enabled all permissions through Settings in an Android 11 mobile. However, if I use ActivityCompat.checkSelfPermission(this,(Manifest ...
Read more >
How to manage app permissions in Android 11 | TechRepublic
To do this, open the Settings app and then go to Apps & Notifications. From there, tap See All X Apps (where X...
Read more >
Android 11 One Time Permission - Medium
In Android 11 (API level 30) whenever your app requests permission related to location, microphone, or camera, permissions dialog will show ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found