Commit 8950fdeb authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

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

parent 3b624527
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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)**.
+0 −1
Changes for plugin.xml: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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>

+16 −14
Changes for src/android/LocalNotification.java: 16 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -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
+14 −0
Changes for www/local-notification.js: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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;