0

I have receiving GCM push notification message in my mobile successfully. But, I want to make some text update in my app working page.

While receiving push notification, app page automatically need to change text like push notification received and show to any text view, in working page.

Already referred: Updating the UI upon receiving an android push notification

For push notification am using this class to receive notification:

public class GCMBroadcastReceiver extends WakefulBroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}

For MainPage Push notif text showing Activity Page Code:

public void onResume(){
    super.onResume() ;
    Log.v("tag","onResume working...")      ;
    broadcast = new BroadcastReceiver() {
    @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(getApplicationContext(), "Receiver...", 1).show();   
        }
    };
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcast,new IntentFilter("com.google.android.c2dm.intent.REGISTRATION"));
}

@Override
protected void onPause() {
    super.onPause();
    LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcast);
}

My above code: exactly don't know the mistake in code..

Shivam Kumar
  • 1,839
  • 1
  • 20
  • 30
harikrishnan
  • 2,075
  • 3
  • 26
  • 60

1 Answers1

1

You have to call a local BroadcastReceiver which will be on your current app page.

To do this- Inside your GcmListenerService class after receiving a message on the override method onMessageReceived(String from, Bundle data) you have to call your local BroadcastReceiver on the base of relevant result from inside the method.

When the BroadcastReceiver will call, now show a message or set a text in TextView from inside the local BroadcastReceiver after getting the intent result.

Hope it will help you.

D_Alpha
  • 3,719
  • 20
  • 35
  • i tried like this ji.. its not working.. can u give some working sample source code. – harikrishnan Oct 03 '16 at 10:35
  • Intent intent = new Intent(this,YourActivity.class); intent.setAction("MyBroadcast"); intent.putExtra("value", "your data if any"); sendBroadcast(intent); // and on your activity class LocalBroadcastManager.getInstance(this).registerReceiver(broadcast,new IntentFilter("MyBroadcast")); – D_Alpha Oct 03 '16 at 10:52