Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/caffeinalab/ti.goosh
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Dec 17, 2017
2 parents b513420 + ad4344c commit 32763b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions android/src/ti/goosh/TiGooshModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -85,13 +86,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);
}
}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 32763b5

Please sign in to comment.