Commit 40cf1f2f1be269776cc9a8af2bcc21c8292477c0

Authored by cuong
1 parent c99e473746

update reponse

Showing 2 changed files with 32 additions and 9 deletions Side-by-side Diff

android/src/main/java/com/reactnativecommunity/rnpermissions/RNPermissionsModule.java
... ... @@ -25,6 +25,7 @@ import com.facebook.react.module.annotations.ReactModule;
25 25 import java.util.HashMap;
26 26 import java.util.Map;
27 27 import android.os.Build;
  28 +import android.util.Log;
28 29  
29 30 import javax.annotation.Nullable;
30 31  
... ... @@ -42,15 +43,27 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
42 43 @Override
43 44 public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
44 45 if (requestCode == OVERLAY_PERMISSION_CODE) {
  46 +// Log.e("TEAGGGG", "OVERLAY_PERMISSION_CODE: "+ requestCode);
45 47 if (mPickerPromise != null) {
46 48 final WritableMap output = Arguments.createMap();
47 49 final WritableMap settings = Arguments.createMap();
48 50 output.putMap("settings", settings);
49   - if (resultCode == Activity.RESULT_CANCELED) {
50   - output.putString("status", "blocked");
51   - } else if (resultCode == Activity.RESULT_OK) {
52   - output.putString("status", "granted");
  51 + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
  52 + final ReactApplicationContext reactContext = getReactApplicationContext();
  53 + if (!Settings.canDrawOverlays(reactContext)) {
  54 + output.putString("status", "blocked");
  55 + } else {
  56 + output.putString("status", "granted");
  57 + }
  58 + } else {
  59 + if (resultCode == Activity.RESULT_CANCELED) {
  60 + output.putString("status", "blocked");
  61 + } else if (resultCode == Activity.RESULT_OK) {
  62 + output.putString("status", "granted");
  63 + }
53 64 }
  65 +
  66 +// Log.e("TEAGGGG", "output: "+ output.toString());
54 67 mPickerPromise.resolve(output);
55 68 }
56 69 }
... ... @@ -193,7 +206,8 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
193 206 }
194 207 }
195 208  
196   -
  209 + //
  210 + //https://developer.android.com/preview/behavior-changes-all#manage_overlay
197 211 @ReactMethod
198 212 public void checkOrRequestOverlayPermission(final Promise promise) {
199 213 // Check if Android M or higher
... ... @@ -217,7 +231,7 @@ public class RNPermissionsModule extends ReactContextBaseJavaModule {
217 231 mPickerPromise.reject("ACTION_MANAGE_OVERLAY_PERMISSION_ERROR", e);
218 232 mPickerPromise = null;
219 233 }
220   - }else{
  234 + } else {
221 235 //default is granted :D
222 236 final WritableMap output = Arguments.createMap();
223 237 final WritableMap settings = Arguments.createMap();
src/module.android.ts
... ... @@ -41,9 +41,18 @@ async function openSettings(): Promise<void> {
41 41  
42 42 async function check(permission: Permission): Promise<PermissionStatus> {
43 43 if (permission == PERMISSIONS.ANDROID.MANAGE_OVERLAY_PERMISSION) {
44   - return (await RNP.checkOrRequestOverlayPermission())
45   - ? RESULTS.BLOCKED
46   - : RESULTS.DENIED;
  44 + console.warn("check MANAGE_OVERLAY_PERMISSION ts")
  45 + const output = await RNP.checkOrRequestOverlayPermission()
  46 + if (output.status == RESULTS.GRANTED) {
  47 + return RESULTS.GRANTED
  48 + } else if (output.status == RESULTS.BLOCKED) {
  49 + return RESULTS.BLOCKED
  50 + } else {
  51 + return RESULTS.UNAVAILABLE
  52 + }
  53 + // return (await RNP.checkOrRequestOverlayPermission())
  54 + // ? RESULTS.BLOCKED
  55 + // : RESULTS.DENIED;
47 56 } else {
48 57 if (!RNP.available.includes(permission)) {
49 58 return RESULTS.UNAVAILABLE;