diff --git a/src/android/NotificationCommands.java b/src/android/NotificationCommands.java index 06cb1ad..f4ee689 100644 --- a/src/android/NotificationCommands.java +++ b/src/android/NotificationCommands.java @@ -10,6 +10,7 @@ import android.util.Log; import org.apache.cordova.PluginResult; import android.service.notification.StatusBarNotification; import android.os.Bundle; +import java.util.Set; public class NotificationCommands extends CordovaPlugin { @@ -83,11 +84,27 @@ public class NotificationCommands extends CordovaPlugin { Bundle extras = n.getNotification().extras; - json.put("title", getExtra(extras, "android.title")); + //json.put("title", getExtra(extras, "android.title")); json.put("package", n.getPackageName()); - json.put("text", getExtra(extras,"android.text")); - json.put("textLines", getExtraLines(extras, "android.textLines")); + //json.put("text", getExtra(extras,"android.text")); + //json.put("textLines", getExtraLines(extras, "android.textLines")); + Set keys = extras.keySet(); + /* Iterate over all keys of the bundle to give back all the information available */ + for (String key : keys) { + try { + String printKey = key; + /* If key has a prefix android., this will be removed. */ + if(printKey.indexOf("android.")==0 && printKey.length()>8){ + printKey = printKey.substring(8,key.length()); + } + // json.put(key, bundle.get(key)); see edit below + json.put(printKey, JSONObject.wrap(extras.get(key))); + } catch(JSONException e) { + Log.d(TAG,e.getMessage()); + } + } + return json; }