Browse Source

NavigationActivity implements PermissionAwareActivity (#470)

* NavigationActivity implements PermissionAwareActivity

* NavigationActivity implements PermissionAwareActivity

* Fixed code styling

* Removed Hungarian notation.

* Removed empty line
Chaitanya Bhagvan 8 years ago
parent
commit
490e66e458

+ 19
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

@@ -1,12 +1,17 @@
1 1
 package com.reactnativenavigation.controllers;
2 2
 
3
+import android.annotation.TargetApi;
3 4
 import android.content.Intent;
5
+import android.os.Build;
4 6
 import android.os.Bundle;
7
+import android.support.annotation.Nullable;
5 8
 import android.support.v7.app.AppCompatActivity;
6 9
 import android.view.KeyEvent;
7 10
 
8 11
 import com.facebook.react.bridge.Callback;
9 12
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
13
+import com.facebook.react.modules.core.PermissionAwareActivity;
14
+import com.facebook.react.modules.core.PermissionListener;
10 15
 import com.reactnativenavigation.NavigationApplication;
11 16
 import com.reactnativenavigation.events.Event;
12 17
 import com.reactnativenavigation.events.EventBus;
@@ -27,7 +32,7 @@ import com.reactnativenavigation.react.JsDevReloadHandler;
27 32
 
28 33
 import java.util.List;
29 34
 
30
-public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, Subscriber {
35
+public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, Subscriber, PermissionAwareActivity {
31 36
 
32 37
     /**
33 38
      * Although we start multiple activities, we make sure to pass Intent.CLEAR_TASK | Intent.NEW_TASK
@@ -42,6 +47,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
42 47
     private ActivityParams activityParams;
43 48
     private ModalController modalController;
44 49
     private Layout layout;
50
+    @Nullable private PermissionListener mPermissionListener;
45 51
 
46 52
     @Override
47 53
     protected void onCreate(Bundle savedInstanceState) {
@@ -312,4 +318,16 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
312 318
         modalController.destroy();
313 319
         layout.destroy();
314 320
     }
321
+
322
+    @TargetApi(Build.VERSION_CODES.M)
323
+    public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
324
+        mPermissionListener = listener;
325
+        requestPermissions(permissions, requestCode);
326
+    }
327
+
328
+    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
329
+        if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
330
+            mPermissionListener = null;
331
+        }
332
+    }
315 333
 }