java - Android notification is not showing it's content when app is not running -
here interesting problem. android notification comes gcm not showing title , content (just shows app name, , when click, open mainactivity) when app not running.
but when app open, it's showing successfully title , content. can problem? running without problem , didn't change anything.
manifest:
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_phone_state" /> <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="android.permission.vibrate" /> <uses-permission android:name="com.google.android.c2dm.permission.receive" /> <uses-permission android:name="com.package.xxx.permission.c2d_message" /> <permission android:name="com.package.xxx.permission.c2d_message" android:protectionlevel="signature" />
<receiver android:name="com.google.android.gms.gcm.gcmreceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> <action android:name="com.google.android.c2dm.intent.registration" /> <category android:name="com.package.xxx" /> </intent-filter> </receiver> <service android:name=".service.gcmservice" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> </intent-filter> </service>
gcmservice.java:
import android.app.notificationmanager; import android.app.pendingintent; import android.content.context; import android.content.intent; import android.os.bundle; import android.support.v4.app.notificationcompat; import android.text.textutils; import android.util.log; import com.google.android.gms.gcm.gcmlistenerservice; import com.package.xxx.activity.readnormal; import com.package.xxx.r; public class gcmservice extends gcmlistenerservice { public gcmservice() { } @override public void onmessagereceived(string from, bundle data) { log.d("gcmservice", data.tostring()); string type = data.getstring("type", ""); if(type.equals("news")) { shownewsnotification(data); } } private void shownewsnotification(bundle data) { string neid = data.getstring("neid"); if(textutils.isempty(neid)) { return; } int id = integer.valueof(neid); notificationcompat.builder mbuilder = new notificationcompat.builder(this) .setcontenttitle(data.getstring("neti")) .setcontenttext("click read more.") .setsmallicon(r.drawable.ic_launcher) .setautocancel(true); intent = new intent(); i.putextra("nesi", data.getstring("nesi")); i.putextra("neur", data.getstring("neur")); i.putextra("neti", data.getstring("neti")); i.putextra("neim", data.getstring("neim")); i.putextra("neid", id); i.setclass(this, readnormal.class); i.setflags(intent.flag_activity_new_task); /***/ pendingintent pi = pendingintent.getactivity(getapplicationcontext(), 0, i, pendingintent.flag_update_current); mbuilder.setcontentintent(pi); notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); mnotificationmanager.notify(0, mbuilder.build()); } @override public void ondeletedmessages() { } @override public void onmessagesent(string msgid) { } @override public void onsenderror(string msgid, string error) { }
thank you.
logs when app running.
d/gcmservice: bundle[{neid=4663755, neim=http://icdn.posta.com.tr/editor/hd/30/1/2016/fft2mm7549077.jpg, nesi=posta, neti=erdoğan: rusya sonucuna katlanır, neur=http://www.posta.com.tr/turkiye/haberdetay/erdogan--rusya-sonucuna-katlanir.htm?articleid=324647, type=news, notification=bundle[{e=1}], collapse_key=com.tekmobil.guncelhaber}]
logs when app not running.
(empty, there no log)
found problem. using 8.4.0 version (up-to-date) of play services.
compile 'com.google.android.gms:play-services-gcm:8.4.0' //gcm
i reduced version 8.3.0
. works expected.
Comments
Post a Comment