Skip to content

Commit a4a6772

Browse files
ericvicentiDanielMSchmidt
authored andcommitted
IntegrationWithExsistingApps Android Update
Summary: Added permission code to handle the user permission accepted or denied cases which causes potential app crashing if not handled. Only a small piece of code added to the guide to resolve an issue I was facing with permission. The app that I was testing following the guide available, it was crashing showing permission denied error on the android monitor, and there was no step for how to resolve the issue. So I tried out a solution so thought would share it on the official Guide to help people who are stuck with the same issue. Closes facebook#11687 Differential Revision: D4377882 Pulled By: ericvicenti fbshipit-source-id: a7db104c7c1b7e1fb2590c83118715840c17927b
1 parent c37d0cd commit a4a6772

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

docs/IntegrationWithExistingApps.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,36 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
726726
}
727727
```
728728

729-
That's it, your activity is ready to run some JavaScript code.
729+
Now your activity is ready to run some JavaScript code.
730730

731-
> If your app is targeting the Android `api level 23` or greater, make sure you have, for the development build, the `overlay permission` enabled. You can check it with `Settings.canDrawOverlays(this);`. This is required because, if your app produces an error in the react native component, the error view is displayed above all the other windows. Due to the new permissions system, introduced in the api level 23, the user needs to approve it.
731+
### Configure permissions for development error overlay
732+
733+
If your app is targeting the Android `API level 23` or greater, make sure you have the `overlay` permission enabled for the development build. You can check it with `Settings.canDrawOverlays(this);`. This is required in dev builds because react native development errors must be displayed above all the other windows. Due to the new permissions system introduced in the API level 23, the user needs to approve it. This can be acheived by adding the following code to the Activity file in the onCreate() method. OVERLAY_PERMISSION_REQ_CODE is a field of the class which would be responsible for passing the result back to the Activity.
734+
735+
```java
736+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
737+
if (!Settings.canDrawOverlays(this)) {
738+
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
739+
Uri.parse("package:" + getPackageName()));
740+
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
741+
}
742+
}
743+
```
744+
745+
Finally, the `onActivityResult()` method (as shown in the code below) has to be overridden to handle the permission Accepted or Denied cases for consistent UX.
746+
747+
```java
748+
@Override
749+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
750+
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
751+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
752+
if (!Settings.canDrawOverlays(this)) {
753+
// SYSTEM_ALERT_WINDOW permission not granted...
754+
}
755+
}
756+
}
757+
}
758+
```
732759

733760
## Run your app
734761

0 commit comments

Comments
 (0)