大佬教程收集整理的这篇文章主要介绍了android – GCM推送通知 – 需要一个接一个地查看移动通知区域中的所有推送警报.,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
目前我正在开发一个Android应用程序,我将收到多个警报(来自服务器),我必须一个接一个地查看所有推送警报(在移动通知列表中).
我在下面给出了我的代码.我的服务器正在成功发送所有GCM推送警报通知到我的Android手机.
但是,我只能查看最后发送的推送警报(在通知列表中).也就是说,考虑我的服务器正在发送2个推送警报:PUSH_A和PUSH_B.在我的Android手机中,我只能查看第二个警报:PUSH_B.
你能说出来,我做错了什么.我必须一个接一个地查看移动设备中的所有推送警报(通知列表中的PUSH_A和PUSH_B).
我的服务器代码如下:
Sender aGcmSender = new Sender(API_KEY); //ConstrucTing message which need to be transmitted to android device. message amessage = new message.builder().addData("message",thePushMsg).build(); Result aResult = aGcmSender.send(amessage,theRegId,1); //TransmitTing message to android device if(aResult != null) { if(aResult.getmessagEID() != null) { String aCanonicalRegistrationId = aResult.getCanonicalRegistrationId(); if(aCanonicalRegistrationId != null) { //updating aCanonicalRegistrationId to my database } itsLogger.info("Push notification successfully sent to cub of phone: "+theCubsPhonE); itsLogger.info("message Id:"+aResult.toString()); } else { String error = aResult.getErrorCodename(); itsLogger.info("Android Push Notification: Failed to send push notification to phone" + thePushMsg); if (error.equals(Constants.ERROR_NOT_REGISTERED)) { // application has been removed from device - unregister database } } }
移动设备中的GCM代码:
* AndroidManifest.xml中:*
<permission android:name="MyProjectPackage.permission.C2D_messaGE" android:protectionLevel="signature" /> <uses-permission android:name="MyProjectPackage.permission.C2D_messaGE" /> <!-- App receives GCM messages. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- GCM requires a Google Account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.READ_owneR_DATA" /> <!-- Keeps the processor from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <!-- BroadcastReceiver for push alert notifications --> <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 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="MyProjectPackage" /> </intent-filter> </receiver> <service android:name=".GCMIntentservice" />
GCMIntentservice:
private void sendGCMIntent(final Context theContext,String themessagE) { int icon = R.drawable.icon; long when = System.currentTimeMillis(); notificationmanager notificationmanager = (notificationmanager) theContext.getSystemservice(Context.NOTIFICATION_serviCE); Notification notification = new Notification(icon,themessage,when); String title = theContext.getString(R.String.app_Name); Intent notificationIntent = new Intent(); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOp); PendingIntent intent = PendingIntent.getActivity(theContext,notificationIntent,0); notification.setLatestEvenTinfo(theContext,title,intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Play default notification sound notification.defaults |= Notification.DEFAULT_SOUND; // Vibrate if vibrate is enabled notification.defaults |= Notification.DEFAULT_VIBRATE; notificationmanager.notify(0,notification); }
请帮忙.
谢谢.
notificationmanager.notify(0,notification);
if (themessage.equals(PUSH_a )) notificationmanager.notify(0,notification); else notificationmanager.notify(1,notification);
以上是大佬教程为你收集整理的android – GCM推送通知 – 需要一个接一个地查看移动通知区域中的所有推送警报.全部内容,希望文章能够帮你解决android – GCM推送通知 – 需要一个接一个地查看移动通知区域中的所有推送警报.所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。