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 @@
<activity
android:name="de.appplant.cordova.plugin.localnotification.ClickActivity"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoDisplay"
android:theme="@android:style/Theme.Translucent"
android:exported="false" />
<receiver
......@@ -121,7 +121,7 @@
<activity
android:name="de.appplant.cordova.plugin.notification.ClickActivity"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoDisplay"
android:theme="@android:style/Theme.Translucent"
android:exported="false" />
</config-file>
......
......@@ -134,7 +134,10 @@ public class LocalNotification extends CordovaPlugin {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
if (action.equals("schedule")) {
if (action.equals("hasPermission")) {
hasPermission(command);
}
else if (action.equals("schedule")) {
schedule(args);
command.success();
}
......@@ -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.
*
* @param notifications
......
......@@ -26,6 +26,7 @@ package de.appplant.cordova.plugin.notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.app.NotificationManagerCompat;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -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.
*
* @param options
......@@ -454,5 +462,12 @@ public class Manager {
return (NotificationManager) context
.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) {
exports.hasPermission = function (callback, scope) {
var fn = this.createCallbackFn(callback, scope);
if (device.platform != 'iOS') {
if (device.platform != 'iOS' && device.platform != 'Android') {
fn(true);
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