Commit 8950fdeb by Sebastián Katzer

GET_TASK permission not needed anymore for Android (solves #123)

parent 3b624527
......@@ -10,6 +10,7 @@
- [enhancement:] Support for bigview style notifications for Android devices.
- [bugfix:] Sound didnt play properly on iOS/Android.
- [bugfix:] click event on iOS wasn't fired if app was not running.
- [enhancement:] GET_TASK permission not needed anymore for Android.
#### Version 0.7.2 (09.02.2014)
- [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**.
......
......@@ -74,7 +74,6 @@
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</config-file>
......
......@@ -34,7 +34,6 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
......@@ -56,7 +55,7 @@ public class LocalNotification extends CordovaPlugin {
private static CordovaWebView webView = null;
private static Boolean deviceready = false;
protected static Context context = null;
protected static Boolean isInBackground = true;
private static ArrayList<String> eventQueue = new ArrayList<String>();
@Override
......@@ -131,6 +130,18 @@ public class LocalNotification extends CordovaPlugin {
return true;
}
if (action.equalsIgnoreCase("pause")) {
isInBackground = true;
return true;
}
if (action.equalsIgnoreCase("resume")) {
isInBackground = false;
return true;
}
// Returning false results in a "MethodNotFound" error.
return false;
}
......@@ -306,10 +317,12 @@ public class LocalNotification extends CordovaPlugin {
* @param {String} json A custom (JSON) string
*/
public static void fireEvent (String event, String id, String json) {
String state = isInBackground() ? "background" : "foreground";
String state = isInBackground ? "background" : "foreground";
String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
String js = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)";
// webview may available, but callbacks needs to be executed
// after deviceready
if (deviceready == false) {
eventQueue.add(js);
} else {
......@@ -346,15 +359,4 @@ public class LocalNotification extends CordovaPlugin {
protected static NotificationManager getNotificationManager () {
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
/**
* Specifies whether the App is running in the background
*/
private static boolean isInBackground () {
try {
return !context.getPackageName().equalsIgnoreCase(((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName());
} catch (Exception e) {
return true;
}
}
}
\ No newline at end of file
......@@ -216,4 +216,18 @@ channel.deviceready.subscribe( function () {
cordova.exec(null, null, 'LocalNotification', 'deviceready', []);
});
channel.onCordovaReady.subscribe( function () {
if (device.platform != 'iOS') {
channel.onPause.subscribe( function () {
cordova.exec(null, null, 'LocalNotification', 'pause', []);
});
channel.onResume.subscribe( function () {
cordova.exec(null, null, 'LocalNotification', 'resume', []);
});
cordova.exec(null, null, 'LocalNotification', 'resume', []);
}
});
module.exports = plugin;
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