android - IBM Mobilefirst 7.1 PushNotifications: Unable to retrieve notification text from background to foreground -
we have integrated tag based , broadcast notifications in our mobilefirst app. able send notifications when app open , user able see notification text. when user kills app , notification arrives in notification panel: user able click on notification , opens app doesn't shows notification text.
please find code below:
/* tagbased , broadcast notification code start */ var chkholder; function suborunsub(chkbxflag){ console.log('the value of checkbox flag is:'+chkbxflag); var checkbox; if(chkbxflag=='tg1') { chkholder = "tag1"; checkbox = document.getelementbyid("subtg1").checked; console.log('the checkbox value is:'+checkbox); if(checkbox) { subscribetonotiftag('tag1'); } else { unsubscribefromnotiftag('tag1'); } } else if(chkbxflag=='tg2') { chkholder = "tag 2"; checkbox = document.getelementbyid("subtg2").checked; console.log('the checkbox value is:'+checkbox); if(checkbox) { subscribetonotiftag('tag2'); } else { unsubscribefromnotiftag('tag2'); } } //---------------------------- check if push support available----------- function ispushsupported() { var issupported = false; if (wl.client.push){ issupported = wl.client.push.ispushsupported(); } wl.simpledialog.show("alert", json.stringify(issupported), [ { text : 'close', handler : function() {} } ]); } // --------------------------------- subscribe tag -------------------- function subscribetonotiftag(ntag) { wl.client.push.subscribetag(ntag, { onsuccess: subscribetagsuccess, onfailure: subscribetagfailure }); } function subscribetagsuccess() { wl.simpledialog.show("alert", "subscribed : "+chkholder, [ { text : 'close', handler : function() {} } ]); } function subscribetagfailure() { wl.simpledialog.show("alert", "failed subscribe : "+chkholder, [ { text : 'close', handler : function() {} } ]); } // ------------------------------- unsubscribe tag -------------------- function unsubscribefromnotiftag(ntag) { wl.client.push.unsubscribetag(ntag, { onsuccess: unsubscribetagsuccess, onfailure: unsubscribetagfailure }); } function unsubscribetagsuccess() { wl.simpledialog.show("alert", "unsubscribed : "+chkholder, [ { text : 'close', handler : function() {} } ]); } function unsubscribetagfailure() { wl.simpledialog.show("alert", "failed unsubscribe : "+chkholder, [ { text : 'close', handler : function() {} } ]); } //------------------------------- handle received notification ----------- wl.client.push.onmessage = function (props) { if(wl.staticappprops.environment=='iphone') { wl.simpledialog.show("alert", "" + json.stringify(props.alert.body), [ { text : 'close', handler : function() {} }]); }else if(wl.staticappprops.environment=='android') { wl.simpledialog.show("alert", "" + json.stringify(props.alert), [ { text : 'close', handler : function() {} }]); } }; /* tagbased , broadcast notification code end */ androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp" android:versioncode="6" android:versionname="8.2"> <uses-sdk android:minsdkversion="10" android:targetsdkversion="21"/> <supports-screens android:smallscreens="false" android:normalscreens="true" android:largescreens="false"/> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.access_wifi_state"/> <!-- push permissions --> <permission android:name="com.myapp.permission.c2d_message" android:protectionlevel="signature"/> <uses-permission android:name="com.myapp.permission.c2d_message"/> <uses-permission android:name="com.google.android.c2dm.permission.receive"/> <uses-permission android:name="android.permission.wake_lock"/> <uses-permission android:name="android.permission.get_accounts"/> <uses-permission android:name="android.permission.use_credentials"/> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="android.permission.access_fine_location"/> <uses-permission android:name="android.permission.access_coarse_location"/> <uses-permission android:name="android.permission.read_calendar"/> <uses-permission android:name="android.permission.write_calendar"/> <application android:label="@string/app_name" android:icon="@drawable/icon"> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasybhvtzepwg4dytg9zsvijz9mric53ehleu"/> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <activity android:name=".myapp" android:label="@string/app_name" android:configchanges="orientation|keyboardhidden|screensize" android:launchmode="singletask" android:theme="@android:style/theme.translucent.notitlebar" android:screenorientation="portrait"> <intent-filter> <action android:name="android.intent.action.main"/> <category android:name="android.intent.category.launcher"/> </intent-filter> <intent-filter> <action android:name="com.myapp.myapp.notification"/> <category android:name="android.intent.category.default"/> </intent-filter> </activity> <activity android:name=".mgmapfragment" android:theme="@style/theme.mgmaptheme"/> <activity android:name=".mgmultimapfragment" android:theme="@style/theme.mgmaptheme"/> <activity android:name=".mgpickermapfragment" android:theme="@style/theme.mgpckrtheme"/> <!-- preference activity --> <activity android:name="com.worklight.common.wlsettingactivity" android:label="worklight settings"/> <!-- ui activity displaying native dialogs --> <activity android:name="com.worklight.wlclient.ui.uiactivity"/> <!-- push service --> <!-- in order use c2dm library, application must declare class name c2dmreceiver, in own package, extending com.google.android.c2dm.c2dmbasereceiver must include section in manifest, replacing "com.google.android.apps.chrometophone" package name. --> <service android:name=".gcmintentservice"/> <service android:name=".foregroundservice"/> <!-- google service can send data messages app. if permission not set - other app can generate --> <receiver android:name="com.worklight.androidgap.push.wlbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send"> <!-- receive actual message --> <intent-filter> <action android:name="com.google.android.c2dm.intent.receive"/> <category android:name="com.myapp"/> </intent-filter> <!-- receive registration id --> <intent-filter> <action android:name="com.google.android.c2dm.intent.registration"/> <category android:name="com.myapp"/> </intent-filter> </receiver> </application> </manifest>
i have tried using default code comes sample app , worked fine. reason behind using "wl.staticappprops.environment" want show notification text users. there best way show notification text users?
what mean "just notification text"? how different default notification? sample app shows how can access notification object , display payload , props. seperately.
function pushnotificationreceived(props, payload) { wl.simpledialog.show("push notifications", "provider notification data: " + json.stringify(props), [ { text : 'close', handler : function() { wl.simpledialog.show("push notifications", "application notification data: " + json.stringify(payload), [ { text : 'close', handler : function() {} }]); } }]); }
Comments
Post a Comment