Odbiornik aktywności - Google Cloud Messaging - odbiorca transmisji

Zaimplementowałem GCM w mojej aplikacji na Androida i działa dobrze z otrzymywaniem wiadomości. BroadcastReceiver jest skonfigurowany w pliku manifestu zgodnie z przykładami dostarczonymi przez Google.

Moje pytanie brzmi: Jeśli użytkownik ma otwartą aplikację i chcę zaktualizować niektóre wyniki w tym widoku - jak można to zrobić? Najpierw myślałem o zarejestrowaniu tej aktywności jako słuchacza na tym, co otrzyma BroadCastReceiver. Musi to być jednak statyczna lista słuchaczy, ponieważ zostanie utworzona nowa instancja odbiornika BroadcastReceiver - ale może nie w ten sposób.

To właśnie mam obecnie

        public class GCMBroadcastReceiver extends WakefulBroadcastReceiver  {

            @Override
            public void onReceive(Context context, Intent intent) {
                ComponentName comp = new ComponentName(context.getPackageName(),
                        GCMIntentService.class.getName());
                startWakefulService(context, (intent.setComponent(comp)));
                setResultCode(Activity.RESULT_OK);
            }
        }


        public class GCMIntentService extends IntentService {
            public static final int NOTIFICATION_ID = 1;
            private NotificationManager mNotificationManager;
            NotificationCompat.Builder builder;

            public GCMIntentService() {
                super("GCMIntentService");
            }

            @Override
            protected void onHandleIntent(Intent intent) {
                Bundle extras = intent.getExtras();
                GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
                String messageType = gcm.getMessageType(intent);

                if (!extras.isEmpty()) {
                   if (GoogleCloudMessaging.
                            MESSAGE_TYPE_MESSAGE.equals(messageType)) {

                     /** How to check if the activity 
GameActivity is running, and hence send an 
update signal to it? If it's not running a 
notification should be created.
    **/
                   }
                }
                GCMBroadcastReceiver.completeWakefulIntent(intent);
            }
        }

Oto ważna część tego pliku manifestu:

       <receiver
            android:name="q.w.e.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

                <category android:name="q.w" />
            </intent-filter>
        </receiver>

        <service android:name="q.w.e.gcm.GCMIntentService" />

Jakakolwiek rada?

Dzięki!

questionAnswers(1)

yourAnswerToTheQuestion