Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android – 如何发送GCM推送通知以及要加载哪些活动的说明?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我能够创建推送通知.但目前我只能让人们登陆主屏幕.

如何将人员发送到特定活动?是否可以添加一些像item_id这样的参数,以便活动知道要加载哪些数据?

或者,如果某个地方有一个很好的教程,那也会很棒.我似乎无法通过谷歌搜索找到很多关于此的信息.

在我的GCMIntentservice中,我有这个方法

@Override
      protected void onmessage(Context ctxt,Intent messagE) 
      {           
        Bundle extras=message.getExtras();

        try
        {
            String question_id = extras.getString("question_id");
//          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( this );
//          Intent intent = new Intent(ctxt,QuestionActivity.class);

            generateNotification(ctxt,extras.getString("message"),"New message"  );           
        }
        catch ( Exception e )
        {
        }
      }

但我不知道如何更改generateNotification以指示该人应该登陆的活动.@H_419_11@谢谢!

解决方法

更新: @H_419_11@给Eran以JSON为荣,我只想详细说明.

您可以使用数据键添加其他参数:

{
   "registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],"data": {
       "stuff": "100","more": "abc"
   },}

然后使用intent.getExtras().getString(“stuff”)以相同的方式访问.

全是here.

然后在你的generateNotifcation()中:

private static void generateNotification(Context context,String messagE) {
    notificationmanager notificationmanager = (notificationmanager)
        context.getSystemservice(Context.NOTIFICATION_serviCE);
    Notification notification = new Notification(R.drawable.ic_launcher,message,when);
    String title = "...";


    //get id from json here and decide which activity to go to...
    Intent notificationIntent = new Intent(context,someClass.class);


    notificationIntent.putExtra("message",messagE);
    PendingIntent intent = PendingIntent.getActivity(context,notificationIntent,PendingIntent.FLAG_updatE_CURRENT);
    notification.setLatestEvenTinfo(context,title,intent);
    notification.defaults|=Notification.DEFAULT_VIBRATE;
    notificationmanager.notify(0,notification);
}

大佬总结

以上是大佬教程为你收集整理的Android – 如何发送GCM推送通知以及要加载哪些活动的说明?全部内容,希望文章能够帮你解决Android – 如何发送GCM推送通知以及要加载哪些活动的说明?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。