栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android-GCM推送通知未出现在通知列表中

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android-GCM推送通知未出现在通知列表中

此代码将在屏幕顶部的android系统栏中生成通知。此代码将创建一个新的意图,该意图将在单击顶部栏中的通知后将用户定向到“
Home.class”。如果您希望它根据当前活动执行特定的操作,则可以将广播请求从GCMIntentService发送到您的其他活动。

Intent notificationIntent=new Intent(context, Home.class);generateNotification(context, message, notificationIntent);private static void generateNotification(Context context, String message, Intent notificationIntent) {    int icon = R.drawable.icon;    long when = System.currentTimeMillis();    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);    Notification notification = new Notification(icon, message, when);    String title = context.getString(R.string.app_name);    // 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(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);    notification.setLatestEventInfo(context, title, message, intent);    notification.flags |= Notification.FLAG_AUTO_CANCEL;    notificationManager.notify(0, notification);}

请注意,此示例使用R.drawable和R.String中的资源,这些资源必须存在才能正常工作,但是应该可以给您带来启发。有关状态通知的更多信息,请参见http://developer.android.com/guide/topics/ui/notifiers/index.html,以及有关广播接收的信息。http://developer.android.com/reference/android/content/BroadcastReceiver.html



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/509665.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号