Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:36:07+00:00 2026-06-14T05:36:07+00:00

Hy guys. I’ve implemented Google Cloud Messaging in my app,but i have a problem

  • 0

Hy guys. I’ve implemented Google Cloud Messaging in my app,but i have a problem when i try to display the message received from the server to the user.
I’ve managed to display the message in a toast,but i would like to use an Alert Dialog.
This is my GCMBaseIntentService:

 public class GCMIntentService extends GCMBaseIntentService {

    public static final String SENDER_ID = "546677596418"; 

    public GCMIntentService() {
       super(SENDER_ID);
    }

    @Override
    protected void onError(Context arg0, String arg1) {
        // TODO Auto-generated method stub
         Log.e("Registration", "Got an error!");
         Log.e("Registration", arg0.toString() + arg1.toString());
    }

    @Override
    protected void onMessage(final Context arg0, final Intent arg1) {
        // TODO Auto-generated method stub
        Log.i("Registration", "Got a message!");
        Log.i("Registration", arg1.getStringExtra("message"));


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


                /*  String msg = arg1.getStringExtra("message");
                if(msg != null){
                    new AlertDialog.Builder(arg0)
                    .setTitle("New Notification")
                    .setMessage(msg)
                    .setNeutralButton("OK", new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                    }).create().show();
                }
              */  
            }         
        });

    }
    }

the commented part is my attempt to display an alert Dialog.I think the context is the problem,but i don’t really know how to fix it.
It would be better if i use notifications for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:36:08+00:00Added an answer on June 14, 2026 at 5:36 am

    i’ve solved the problem using notifications.I guess this will have to do:)

    @Override
        protected void onMessage(final Context arg0, final Intent arg1) {
            // TODO Auto-generated method stub
            Log.i("Registration", "Got a message!");
            Log.i("Registration", arg1.getStringExtra("message"));
            String message= arg1.getStringExtra("message");
    
          generateNotification(getApplicationContext(), message);
    
    private  void generateNotification(Context context, String message)
            {
    
    
    
                // Creates an explicit intent for an Activity in your app
                Intent resultIntent = new Intent(context, BBCAndroid.class);
    
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    
                mBuilder.setContentTitle("BBC Android")
                        .setContentText(message)
                        .setSmallIcon(R.drawable.notification);
    
    
                PendingIntent in = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, 0);
                mBuilder.setContentIntent(in);
    
                mNotificationManager.notify(0, mBuilder.build());
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys. I have a strange problem. I try to write unit-tests to web-app. I
guys, I have iOS app, which running good on ios5.0, but on 4.3.3 it's
guys i am doing google docs integration in my iphone app, i have used
guys! I have problem with my .net application. When I try to print in
Guys I have been trying lots of different options from cutting up to building
Guys. I use getpixel & getdata to retrieve data from the same pic.but some
Guys, for some reason EL is not telling actions from properties. I have this
guys, i would like to know if sorl-thumbnail have any option to crop from
Guys I have an activity which has a home button, when the button is
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.