Browse Source

Merge branch 'master' of https://github.com/jbpin/react-native-permissions into jbpin-master

# Conflicts:
#	ReactNativePermissions.js
#	android/build.gradle
Yonah Forst 7 years ago
parent
commit
29b16c2f90

+ 1
- 0
ReactNativePermissions.js View File

26
 		'event',
26
 		'event',
27
 		'photo',
27
 		'photo',
28
 		'storage'
28
 		'storage'
29
+		'notification',
29
 	]
30
 	]
30
 }
31
 }
31
 
32
 

+ 15
- 0
android/src/main/java/com/joshblour/reactnativepermissions/ReactNativePermissionsModule.java View File

5
 import android.net.Uri;
5
 import android.net.Uri;
6
 import android.provider.Settings;
6
 import android.provider.Settings;
7
 import android.support.v4.app.ActivityCompat;
7
 import android.support.v4.app.ActivityCompat;
8
+import android.support.v4.app.NotificationManagerCompat;
8
 import android.support.v4.content.ContextCompat;
9
 import android.support.v4.content.ContextCompat;
9
 import android.support.v4.content.PermissionChecker;
10
 import android.support.v4.content.PermissionChecker;
10
 
11
 
23
 public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
24
 public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
24
   private final ReactApplicationContext reactContext;
25
   private final ReactApplicationContext reactContext;
25
   private final PermissionsModule mPermissionsModule;
26
   private final PermissionsModule mPermissionsModule;
27
+  private final NotificationManagerCompat mNotificationManagerCompat;
26
 
28
 
27
   public enum RNType {
29
   public enum RNType {
28
     LOCATION,
30
     LOCATION,
31
+    NOTIFICATION,
29
     CAMERA,
32
     CAMERA,
30
     MICROPHONE,
33
     MICROPHONE,
31
     CONTACTS,
34
     CONTACTS,
38
     super(reactContext);
41
     super(reactContext);
39
     this.reactContext = reactContext;
42
     this.reactContext = reactContext;
40
     mPermissionsModule = new PermissionsModule(this.reactContext);
43
     mPermissionsModule = new PermissionsModule(this.reactContext);
44
+    mNotificationManagerCompat = NotificationManagerCompat.from(this.reactContext);
41
   }
45
   }
42
 
46
 
43
   @Override
47
   @Override
55
       return;
59
       return;
56
     }
60
     }
57
 
61
 
62
+    if(permission.equals("notification")) {
63
+      if (mNotificationManagerCompat.areNotificationsEnabled()) {
64
+        promise.resolve("authorized");
65
+      } else {
66
+        promise.resolve("denied");
67
+      }
68
+      return;
69
+    }
70
+
58
     int result = PermissionChecker.checkSelfPermission(this.reactContext, permission);
71
     int result = PermissionChecker.checkSelfPermission(this.reactContext, permission);
59
     switch (result) {
72
     switch (result) {
60
       case PermissionChecker.PERMISSION_DENIED:
73
       case PermissionChecker.PERMISSION_DENIED:
131
       case STORAGE:
144
       case STORAGE:
132
       case PHOTO:
145
       case PHOTO:
133
         return Manifest.permission.READ_EXTERNAL_STORAGE;
146
         return Manifest.permission.READ_EXTERNAL_STORAGE;
147
+      case NOTIFICATION:
148
+        return permission;
134
       default:
149
       default:
135
         return null;
150
         return null;
136
     }
151
     }