android– 在GCMBaseIntentService中显示toast

android– 在GCMBaseIntentService中显示toast,第1张

概述我正在尝试实现推送通知客户端.我想在onMessage(Contextarg0,Intentarg1)函数中显示toast.这是我的代码:publicclassGCMIntentServiceextendsGCMBaseIntentService{staticContextc;@SuppressWarnings("hiding")privatestaticfinalStringTAG="GCMIntentServ

我正在尝试实现推送通知客户端.我想在onMessage(Context arg0,Intent arg1)函数中显示toast.

这是我的代码:

    public class GCMIntentService extends GCMBaseIntentService {static Context c;@SuppressWarnings("hIDing")private static final String TAG = "GCMIntentService";public GCMIntentService() {    super("717816998404");    c = this.getBaseContext();}/** * Issues a notification to inform the user that server has sent a message. */@OverrIDeprotected voID one rror(Context arg0, String arg1) {    // Todo auto-generated method stub}@OverrIDeprotected voID onMessage(Context arg0, Intent arg1) {    Log.d("GCM", "RECIEVED A MESSAGE");    Log.d("GCM", "RECIEVED A MESSAGE");    Log.d("GCM", "RECIEVED A MESSAGE");    Log.d("GCM", "RECIEVED A MESSAGE");    Log.d("GCM", "RECIEVED A MESSAGE");    Log.d("GCM", "RECIEVED A MESSAGE");    Log.d("GCM", "RECIEVED A MESSAGE");    String str =arg1.getExtras().getString("PVAL");    Log.i("PVAL",str);    // I want to display a toast here}@OverrIDeprotected voID onRegistered(Context arg0, String arg1) {    // Todo auto-generated method stub    Log.i("TEST", arg1);    Log.e("TEST", arg1);}@OverrIDeprotected voID onUnregistered(Context arg0, String arg1) {    // Todo auto-generated method stub}

}

我想知道如何显示收到的消息我试图显示吐司检查消息.

解决方法:

试试这个:

Handler h = new Handler(Looper.getMainLooper());       h.post(new Runnable(){            public voID run() {                // Todo auto-generated method stub            Toast.makeText(arg0, arg1.getStringExtra("message"), Toast.LENGTH_LONG).show();    }                 });
总结

以上是内存溢出为你收集整理的android – 在GCMBaseIntentService中显示toast全部内容,希望文章能够帮你解决android – 在GCMBaseIntentService中显示toast所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1120018.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存