From 74b28f911e18d239fad6eee790bd373cb1941db6 Mon Sep 17 00:00:00 2001 From: CHAOUCHE Said Date: Sun, 5 Nov 2017 20:39:20 +0100 Subject: [PATCH 1/2] Fix bug null pointer exception : println needs a message for android before lollipop on call registerForPushNotifications --- android/src/ti/goosh/TiGooshModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/src/ti/goosh/TiGooshModule.java b/android/src/ti/goosh/TiGooshModule.java index ddc2c13..d67bea5 100644 --- a/android/src/ti/goosh/TiGooshModule.java +++ b/android/src/ti/goosh/TiGooshModule.java @@ -85,13 +85,13 @@ public void parseBootIntent() { } } - if (!notification.isEmpty()) { + if (notification != null && !notification.isEmpty()) { sendMessage(notification, true); } else { Log.d(LCAT, "No notification in Intent"); } } catch (Exception ex) { - Log.e(LCAT, ex.getMessage()); + Log.e(LCAT, "parseBootIntent" + ex); } } From 9518a9a74eaddee0cc841ad3951f913bafa2128e Mon Sep 17 00:00:00 2001 From: CHAOUCHE Said Date: Sun, 5 Nov 2017 22:04:21 +0100 Subject: [PATCH 2/2] Add methode areNotificationEnabled --- README.md | 6 ++++++ android/src/ti/goosh/TiGooshModule.java | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index a2a510c..b328b64 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,13 @@ TiGoosh.registerForPushNotifications({ ```js TiGoosh.unregisterForPushNotifications(); ``` +## Are notifications enabled +It will return false if users have disabled notifications from the settings for the app, work from to API 19 (Android 4.4). +Not work for android before API 19 (Android 4.4), return true. +```js +TiGoosh.areNotificationsEnabled(); +``` ## Usage with Trimethyl [Trimethyl](http://trimethyl.github.io/trimethyl/) uses this module for its *Notifications* library. [http://trimethyl.github.io/trimethyl/notifications.js.html#line155](http://trimethyl.github.io/trimethyl/notifications.js.html#line155), so you can just type: diff --git a/android/src/ti/goosh/TiGooshModule.java b/android/src/ti/goosh/TiGooshModule.java index d67bea5..1374160 100644 --- a/android/src/ti/goosh/TiGooshModule.java +++ b/android/src/ti/goosh/TiGooshModule.java @@ -39,6 +39,7 @@ import com.google.android.gms.iid.InstanceID; import android.app.NotificationManager; +import android.support.v4.app.NotificationManagerCompat; @Kroll.module(name="TiGoosh", id="ti.goosh") public class TiGooshModule extends KrollModule { @@ -160,6 +161,15 @@ protected Void doInBackground(Void... params) { }.execute(); } + @Kroll.method + public boolean areNotificationsEnabled() { + try{ + return NotificationManagerCompat.from(TiApplication.getInstance().getApplicationContext()).areNotificationsEnabled(); + }catch(Exception ex){ + return false; + } + + } @Kroll.method public void cancelAll() {