Explorar el Código

added android notification support

Jean-Baptiste Pin hace 8 años
padre
commit
584a76e9d7

+ 4
- 3
ReactNativePermissions.js Ver fichero

@@ -15,7 +15,7 @@ const RNPTypes = {
15 15
 		'reminder',
16 16
 		'bluetooth',
17 17
 		'notification',
18
-		'backgroundRefresh', 
18
+		'backgroundRefresh',
19 19
 	],
20 20
 	android: [
21 21
 		'location',
@@ -24,6 +24,7 @@ const RNPTypes = {
24 24
 		'contacts',
25 25
 		'event',
26 26
 		'photos',
27
+		'notification',
27 28
 	]
28 29
 }
29 30
 
@@ -66,7 +67,7 @@ class ReactNativePermissions {
66 67
 	}
67 68
 
68 69
 	requestPermission(permission, type) {
69
-		let options; 
70
+		let options;
70 71
 
71 72
 		if (!this.getPermissionTypes().includes(permission)) {
72 73
 			return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on ${Platform.OS}`)
@@ -89,7 +90,7 @@ class ReactNativePermissions {
89 90
 		function processNext() {
90 91
 			i--
91 92
 			let p = permissions[i]
92
-			
93
+
93 94
 			if (!p) {
94 95
 				return Promise.resolve(obj)
95 96
 			}

+ 5
- 4
android/build.gradle Ver fichero

@@ -1,6 +1,6 @@
1 1
 buildscript {
2 2
     repositories {
3
-        jcenter()
3
+        mavenCentral()
4 4
     }
5 5
 
6 6
     dependencies {
@@ -11,12 +11,12 @@ buildscript {
11 11
 apply plugin: 'com.android.library'
12 12
 
13 13
 android {
14
-    compileSdkVersion 23
15
-    buildToolsVersion "23.0.1"
14
+    compileSdkVersion 24
15
+    buildToolsVersion "24.0.1"
16 16
 
17 17
     defaultConfig {
18 18
         minSdkVersion 18
19
-        targetSdkVersion 23
19
+        targetSdkVersion 24
20 20
         versionCode 1
21 21
         versionName "1.0"
22 22
     }
@@ -31,4 +31,5 @@ repositories {
31 31
 
32 32
 dependencies {
33 33
     compile 'com.facebook.react:react-native:+'
34
+    compile 'com.android.support:support-v4:24.1.1'
34 35
 }

+ 4
- 3
android/src/main/java/com/joshblour/reactnativepermissions/ReactNativePermissionsModule.java Ver fichero

@@ -22,6 +22,7 @@ import com.facebook.react.modules.permissions.PermissionsModule;
22 22
 public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
23 23
   private final ReactApplicationContext reactContext;
24 24
   private final PermissionsModule mPermissionsModule;
25
+  private final NotificationManagerCompat mNotificationManagerCompat;
25 26
 
26 27
   public enum RNType {
27 28
     LOCATION,
@@ -37,7 +38,7 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
37 38
     super(reactContext);
38 39
     this.reactContext = reactContext;
39 40
     mPermissionsModule = new PermissionsModule(this.reactContext);
40
-    this.notificationManagerCompat = NotificationManagerCompat.from(reactContext);
41
+    mNotificationManagerCompat = NotificationManagerCompat.from(this.reactContext);
41 42
   }
42 43
 
43 44
   @Override
@@ -55,8 +56,8 @@ public class ReactNativePermissionsModule extends ReactContextBaseJavaModule {
55 56
       return;
56 57
     }
57 58
 
58
-    if(permission == 'notification') {
59
-      if (this.notificationManagerCompat.areNotificationsEnabled()) {
59
+    if(permission.equals('notification')) {
60
+      if (mNotificationManagerCompat.areNotificationsEnabled()) {
60 61
         promise.resolve("authorized");
61 62
       } else {
62 63
         promise.resolve("denied");