From 8ada2da3c046f5d5e1ac86a3039006eefdaf3158 Mon Sep 17 00:00:00 2001 From: Sebastian Bittmann Date: Wed, 23 May 2018 23:57:33 +0200 Subject: [PATCH] Added the complete information of the extras bundle to the json object return --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/android/NotificationCommands.java | 37 ++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..682cf4f7677c5a850c0fd5e636884caf03345355 GIT binary patch literal 6148 zcmeHK-HOvd6h6~dO|unyA?$jW8^MbrZK22_3*Byu7F5KDUa0IQP3cC{q%^77wN`TD zOXw5$D&BbMgZKdY&5zQg>)j%<%qcV9nKS2`nS5<#Iz+^J3$H~~Cn5udW5q;uhVg!0 zHmsx~H6RmX+@k^6bej@7*~r!bt$RJkEMRLof&6*{J1PUu1nLuxd0Theq@U^@PS?y{4EV3iGqE?E=pPFQ5fDK80YN z(3FA#=VO6Wr6*X|KK1FLSl^Vq0^>)4QNvos*u4@l%LFaHz8OvOypmJkm6188Q6cNw z*;#HH&y=oT-C5wrNwfK#mCBV%m#-LxX_!~dSN3s~+KH1a;+`{q!CQ}=TL`AE$@)>jzPoIDR;u3$pKxk@E7nA9_*Rix#05i*an(VHj1TdRV`)T(<8t8&aRmTY5EcfX|5@N1OJP@GCJ{X_CaFM4W$KE-Bpq=}<#iQi5+$9Ox_mG- zGgCJdCT7R@mPjYom8fg2fL0){Kv_2H{QMvM{r;aP>6TVND{!F{V3oez@8OZu*}Cy? w{H(Q5j!?MqyiB5?pi;-NaQIQYgCY!l7I%PMg_%S|VET`MkU>{kfq$yNFFeA)V*mgE literal 0 HcmV?d00001 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..635047cd741dd3b48570c859ec9ba2736bfa33e9 GIT binary patch literal 6148 zcmeHKPfIH?5TDfgOeuBD79OdlFz zh;|cw9wrmf+%Sy{(Av#G04YS!gIDXPL-f#Zv5C6=WCX2==x~r-g^7uN2(OYj%NvbH zQJN{w{+g4rDys|C6aP{V{5;6}StsZnQEe~CFGFYVYn{B)oPCFYS?VGH|nb0-WZK4a(S)! zXZP&y|Lft+==RRc1O)!IMiw28;U0~5tVG#)65>cH<(=!F-%AsnUZ7{(;kYA4W`G%B z2Bwk$w^_;gsT>^-iWy)AzLNpk9~3H~=diG7whk=J69AE}kw(y_OC#kdhn~a2B6?7S zO+~b+!aXsBO~-cS;yj0iMVk)7JwAl{vT!dHVZM(2D-#aFv&bbgzzn=)V8&K!bpG#r z{{DZP#5HDs8Te5Qi1N0--N7ljvvp!}bk-`=GgK0aD=faGpka<;jHRP^1=R?)D>4v0 UhlNFKLE(#lp@9o#;7b{J1{N7*c>n+a literal 0 HcmV?d00001 diff --git a/src/android/NotificationCommands.java b/src/android/NotificationCommands.java index 06cb1ad..a2f1958 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 { @@ -82,29 +83,25 @@ public class NotificationCommands extends CordovaPlugin { JSONObject json = new JSONObject(); Bundle extras = n.getNotification().extras; - - 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")); + + 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; } - private static String getExtraLines(Bundle extras, String extra){ - try { - CharSequence[] lines = extras.getCharSequenceArray(extra); - return lines[lines.length-1].toString(); - } catch( Exception e){ - Log.d(TAG, "Unable to get extra lines " + extra); - return ""; - } - } - private static String getExtra(Bundle extras, String extra){ - try { - return extras.get(extra).toString(); - } catch( Exception e){ - return ""; - } - } }