google developer를 보며 GCM Receive Message를 구현해보고 있습니다.
GcmIntentService 에서 받은 GCM Message를 Activity에 보내서 UI로 표시해주고 싶은데요.
질문은 아래와 같습니다! 고수님들의 답변 부탁드립니다. ㅠ
1. GcmIntentService의 값을 Activity로 전달하려면 어떻게 해야하나요?
(notification에서 표시해주는 내용만 있는데, UI에 표시하는 방법을 모르겠습니다 ㅠ)
2. GcmIntentService의 마지막에 GcmBroadcastReceiver.completeWakefulIntent(intent); 는
Gcm Message를 GcmBroadCastReceiver로 전달해주나요?
그렇다면 GcmBraodCastReceiver에서는 이 값을 어떻게 받을 수 있나요?
3. Activity로 값을 전달할 때, GcmIntentService -> GcmBroadCastReceiver -> Activity 순으로 전달해야 하나요?
아니면 바로 GcmIntentService -> Activity로 전달하나요?
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
private String TAG = "GcmIntentService";
public GcmIntentService() {
super("GcmIntentService");
Log.d("GcmIntentService","GcmIntentService.constructor");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("GcmIntentService","onHandleIntent");
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) { // has effect of unparcelling Bundle
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " +
extras.toString());
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
intent.putExtra("msg",extras.toString());
sendNotification("Received: " + extras.toString());
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
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);
}
}