Fixing problems in React-Native caused by new permission model on Android
From Android 6.0(version 23) there are big changes in permission model that forces developers to request permissions at runtime.
Not all developers knows about that and this cause such exceptions like:
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@86fb55b -- permission denied for this window type
or
java.io.FileNotFoundException·/storage/emulated/0/Android/obb/com.example.app/main.1.com.example.app.obb: open failed: EACCES (Permission denied)
I will show how to fix this for React-Native apps. Here is MainActivity example:
So there are two thing that you should request at runtime:
1) Window overlay permissions (for all react-native apps)
2) Dangerous permissions that your app may use
For the first one we need to create custom intent, for the second there is special methods of Activity requestPermissions, checkSelfPermission andonRequestPermissionsResult and as you see from example it pretty simple to use them.
Also you can read more about new permission model here.
Don’t forget to checkout my new Android App for removing stress:http://goo.gl/Iz8r5u