android – GCM通知的自定义UI

android – GCM通知的自定义UI,第1张

概述在 GCM Docs它给出: It does not provide any built-in user interface or other handling for message data. GCM simply passes raw message data received straight to the Android application, which has full contr 在 GCM Docs它给出:

It does not provIDe any built-in user interface or other handling for
message data. GCM simply passes raw message data received straight to
the AndroID application,which has full control of how to handle it.
For example,the application might post a notification,display a
custom user interface,or silently sync data

但没有关于如何创建自定义通知UI的任何内容.

如何创建一个自定义用户界面,比如说一个带有2个按钮等的小对话框,用于GCM通知.像gmail一样,可以选择从状态栏通知中归档或删除邮件.

码:

public voID onReceive(Context context,Intent intent) {    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);    ctx = context;    String messageType = gcm.getMessageType(intent);    if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {    } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED            .equals(messageType)) {    } else {        sendNotification(intent.getExtras().getString("msg"));    }    setResultCode(Activity.RESulT_OK);}private voID sendNotification(String msg) {    mnotificationmanager = (notificationmanager) ctx            .getSystemService(Context.NOTIFICATION_SERVICE);    PendingIntent contentIntent = PendingIntent.getActivity(ctx,new Intent(ctx,NotificationsActivity.class),0);    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(            ctx).setSmallicon(R.drawable.ic_launcher)            .setContentTitle("GCM Notification")            .setContentText(msg);    mBuilder.setContentIntent(contentIntent);    Notification mNotification = mBuilder.getNotification();    SharedPreferences sp = ctx.getSharedPreferences(            GCMDemoActivity.GCM_NOTIF_PREF,Context.MODE_PRIVATE);    long diff = System.currentTimeMillis()            - sp.getLong("last_gcm_timestamp",0);    if (diff > TWO_MINUTES) {        mNotification.defaults = Notification.DEFAulT_ALL;        SharedPreferences.Editor editor = sp.edit();        editor.putLong("last_gcm_timestamp",System.currentTimeMillis());        editor.commit();    }    mnotificationmanager.notify(NOTIFICATION_ID,mNotification);}

谢谢

解决方法

But nothing about how to create a custom notification UI.

因为这与GCM无关.

How to create a custom UI like say a small dialog with 2 buttons etc..,for a GCM notification. like gmail gives an option to archive or delete the mail from the status bar notification.

这是一个扩展或“大”的通知,如the documentation所述.

总结

以上是内存溢出为你收集整理的android – GCM通知的自定义UI全部内容,希望文章能够帮你解决android – GCM通知的自定义UI所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1129246.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存