마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GcmIntentService에서 받은 값을 Activity로 전달하고 싶습니다.

0 추천

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

 

토마토큐브 (190 포인트) 님이 2014년 7월 11일 질문
액티비티가 실행되고 있을 때를 이야기하시는건가요?

1개의 답변

0 추천
액티비티에 커스텀 리시버를 만들고 GcmIntentService에서 커스텀 리시버에 값을 실어 호출하면 되실겁니다.
nicehee (73,100 포인트) 님이 2014년 7월 13일 답변
...