GCM관련 구현을 했는습니다. 샘플 보고 작성했습니다.
하지만, 앱이 미실행시 메세지가 오면 notification쪽에 표시가 되고 클릭을 하면. 메세지 표시하는 Activity실행을 하는데.
메세지가 표시가 안됩니다...
앱 실행시네는 메세지 표시하는 Activity쪽에 메세지가 표시가 잘 됩니다.
소스
GCMIntentService.java
protected void onMessage(Context context, Intent intent) {
String message = intent.getExtras().getString("message");
displayMessage(context, message);
// notifies user 메세지 수신하면. 자동으로 앱콜하고 폰 상단에 표시한.
generateNotification(context, message);
}
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class); <--메세지 표시한 Activity
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
//메세지를 전달하고자 정의
static void displayMessage(Context context, String message) {
Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
intent.putExtra(EXTRA_MESSAGE, message);
context.sendBroadcast(intent);
}
위쪽 소스를 보시면...
앱실행시 displayMessage쪽에서 메세지 표시하는 Activity쪽으로 Broadcast합니다. 그럼. BroadcastReceiver에서 메세지를
잘 받아 화면에서 표시합니다..
하지만, 미실행시네는 Notification오면 상태표시하고. 클릭을 하면.. displayMessage에서 Broadcast하는데.. 메세지를 표시를 못합니다.
고수님 어떻게 처리하면 해결이 될까요 ?
도와주세요