Skip to content

Commit

Permalink
Merge pull request #9669 from ypbnv/TIMOB-25591
Browse files Browse the repository at this point in the history
[TIMOB-25591] Android: Programmatically check whether app has notification permission on Android.
  • Loading branch information
Lokesh Choudhary committed Feb 26, 2018
2 parents 7df6a0b + 57dcd53 commit 84b1bdf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.os.Build;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.v4.app.NotificationManagerCompat;

import java.util.HashMap;

Expand Down Expand Up @@ -126,6 +127,12 @@ public void notify(int id, NotificationProxy notificationProxy)
}
}

@Kroll.method
public boolean areNotificationsEnabled()
{
return NotificationManagerCompat.from(TiApplication.getInstance()).areNotificationsEnabled();
}

@Override
public String getApiName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ methods:
returns:
type: Titanium.Android.NotificationChannel

- name: areNotificationsEnabled
summary: Returns whether showing notifications is enabled for the application.
returns:
type: Boolean
since: "7.1.0"

properties:

- name: DEFAULT_ALL
Expand Down
16 changes: 16 additions & 0 deletions tests/Resources/ti.android.notificationmanager.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Axway Appcelerator Titanium Mobile
* Copyright (c) 2011-2018 by Axway Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.Android.NotificationManager', function () {
it.android('Notifications enabled by default', function () {
var notificationEnabled = Ti.Android.NotificationManager.areNotificationsEnabled();
should(notificationEnabled).be.a.Boolean;
should(notificationEnabled).eql(true);
});
});

0 comments on commit 84b1bdf

Please sign in to comment.