Commit 251a7ccf by Alexander Köhn Committed by Sebastián Katzer

Implement 'hasPermission' for Android (#1362)

* changed NoDisplay theme to Translucent
The ClickActivity crashes on Android 6.0.1
See https://web.archive.org/web/20151116170752/https://code.google.com/p/android-developer-preview/issues/detail?id=2353 for solution

* Implement hasPermission for Android (API version >= 22)
parent b9fcd160
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
<activity <activity
android:name="de.appplant.cordova.plugin.localnotification.ClickActivity" android:name="de.appplant.cordova.plugin.localnotification.ClickActivity"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoDisplay" android:theme="@android:style/Theme.Translucent"
android:exported="false" /> android:exported="false" />
<receiver <receiver
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
<activity <activity
android:name="de.appplant.cordova.plugin.notification.ClickActivity" android:name="de.appplant.cordova.plugin.notification.ClickActivity"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoDisplay" android:theme="@android:style/Theme.Translucent"
android:exported="false" /> android:exported="false" />
</config-file> </config-file>
......
...@@ -134,7 +134,10 @@ public class LocalNotification extends CordovaPlugin { ...@@ -134,7 +134,10 @@ public class LocalNotification extends CordovaPlugin {
cordova.getThreadPool().execute(new Runnable() { cordova.getThreadPool().execute(new Runnable() {
public void run() { public void run() {
if (action.equals("schedule")) { if (action.equals("hasPermission")) {
hasPermission(command);
}
else if (action.equals("schedule")) {
schedule(args); schedule(args);
command.success(); command.success();
} }
...@@ -204,6 +207,17 @@ public class LocalNotification extends CordovaPlugin { ...@@ -204,6 +207,17 @@ public class LocalNotification extends CordovaPlugin {
} }
/** /**
* Ask if user has enabled permission for local notifications.
*
* @param command
* The callback context used when calling back into JavaScript.
*/
private void hasPermission (CallbackContext command) {
PluginResult result = new PluginResult(PluginResult.Status.OK, getNotificationMgr().hasPermission());
command.sendPluginResult(result);
}
/**
* Schedule multiple local notifications. * Schedule multiple local notifications.
* *
* @param notifications * @param notifications
......
...@@ -26,6 +26,7 @@ package de.appplant.cordova.plugin.notification; ...@@ -26,6 +26,7 @@ package de.appplant.cordova.plugin.notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.v4.app.NotificationManagerCompat;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -69,6 +70,13 @@ public class Manager { ...@@ -69,6 +70,13 @@ public class Manager {
} }
/** /**
* Check if app has local notification permission.
*/
public boolean hasPermission () {
return getNotMgrCompat().areNotificationsEnabled();
}
/**
* Schedule local notification specified by JSON object. * Schedule local notification specified by JSON object.
* *
* @param options * @param options
...@@ -454,5 +462,12 @@ public class Manager { ...@@ -454,5 +462,12 @@ public class Manager {
return (NotificationManager) context return (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
} }
/**
* Notification manager compat for the application.
*/
private NotificationManagerCompat getNotMgrCompat () {
return NotificationManagerCompat.from(context);
}
} }
...@@ -419,7 +419,7 @@ exports.getAllTriggered = function (callback, scope) { ...@@ -419,7 +419,7 @@ exports.getAllTriggered = function (callback, scope) {
exports.hasPermission = function (callback, scope) { exports.hasPermission = function (callback, scope) {
var fn = this.createCallbackFn(callback, scope); var fn = this.createCallbackFn(callback, scope);
if (device.platform != 'iOS') { if (device.platform != 'iOS' && device.platform != 'Android') {
fn(true); fn(true);
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment