Android – display toast in gcmbaseintentservice

I'm trying to implement a push notification client. I want to display toast in the onmessage (context arg0, intent arg1) function

This is my code:

    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.
 */

@Override
protected void one rror(Context arg0, String arg1) {
    // TODO Auto-generated method stub

}

@Override
protected 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

}

@Override
protected void onRegistered(Context arg0, String arg1) {
    // TODO Auto-generated method stub
    Log.i("TEST", arg1);
    Log.e("TEST", arg1);

}

@Override
protected void onUnregistered(Context arg0, String arg1) {
    // TODO Auto-generated method stub

}

}

I want to know how to display the received message. I try to display the toast check message

resolvent:

Try this:

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();
    }         
        });

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>