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

GCM 푸시 메세지 확인 안하고 계속 받을경우 쌓아놨다가 보여주는 방법좀 알려주세요

0 추천
//푸시로 받은 메세지
  if(intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")){
   msg = intent.getExtras().getString("msg");
   msg2 = intent.getExtras().getString("msg2");
   
   msg2 = URLDecoder.decode(msg2);
   
  }

 

푸시로 메세지를 이렇게 받고

 

 

Handler h = new Handler(Looper.getMainLooper());
  h.post(new Runnable() {
   public void run() {
    //토스트로 푸시된 메세지 띄우기
    Toast.makeText(GCMIntentService.this, "show Toast...."+msg + "  " + msg2, Toast.LENGTH_SHORT).show();
    
    //진동주기
    Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    long milliseconds = 1000;
    vibrator.vibrate(milliseconds);
    
    //화면켜기
    PowerManager powerManager = (PowerManager) context.getSystemService( Context.POWER_SERVICE );
 
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(
      PowerManager.SCREEN_DIM_WAKE_LOCK |
      PowerManager.ACQUIRE_CAUSES_WAKEUP
      , "TEST_1" );
 
    /* 10초 동안 화면 및 cpu 활성화 */
    wakeLock.acquire( 10000 );
    
    //상태바 공지
    NotificationManager nm = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE );
    Notification notification = new Notification(R.drawable.ic_launcher, "새글등록" + msg2, System.currentTimeMillis());
 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent( context, tam.Taxi.TamsTaxi.MainActivity.class ), 0);
    notification.setLatestEventInfo(context, "새글등록", msg, pendingIntent);
    //해당 메세지 선택시 상태바 아이콘 삭제
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    nm.cancel( 0 );
    nm.notify( 0, notification );
 
   }
  });

 

이렇게 메세지를 상태창에 등록하고 클릭하면 사라지고 메인 엑티비티가 뜨게 했습니다

 

그런데 메세지를 여러번 받았을 경우 그동안 받은 메세지를 배열이나 리스트에 쌓아놨다가 상태표시줄에 있는 아이콘 클릭시 그동안 쌓여있는 메세지를 다 보여줬으면 합니다

카톡같은 경우에는 메세지가 몇개 쌓여있는지 숫자를 보여주고 마지막 메세지를 짧게 보여주던데

 

숫자를 카운트 할수 있다면 그동안 받은 메세지도 쌓아놓을수 있지 않을가하는데...

방법을 몰라서요 고수님들 도와주세요~~~

ㅠ.ㅠ
김기훈 (390 포인트) 님이 2013년 7월 10일 질문

1개의 답변

0 추천
메시지를 쌓아놓는건 sqlite나 서버에 하셔야 합니다

대부분 저걸 BroadcastReceiver에서 할 텐데, onReceive가 끝나면 BroadcastReceiver의 생명주기는 끝이납니다.

배열이 사라지죠

 

카카오톡처럼 숫자를 설정하는 방법은

Notification.Builder.setNumber(int);

메소드를 참고하세요

 

당연하지만 객체이구요 (정식 표기법이죠 ㅋ)

 

카카오톡처럼 마지막 메시지를 보여주고 싶으시면 서비스로 하셔서

Notification.Builder을 메모리상에 유지하시면 됩니다

 

nm.notify(int, builder.setContent(?).setNumber(number++).build());

 

setContent가 맞는진 모르겠습니다
GozaMaker (4,740 포인트) 님이 2013년 7월 11일 답변
...