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

gcm 푸시 노티피케이션 질문 있습니다..

0 추천
public class GCMIntentService extends GCMBaseIntentService implements NetDefine {
 
    private static final String TAG = "GCM Tutorial::Service";
 
    public static NextListener listener;
 
    public GCMIntentService() {
        super(SENDER_ID);
    }
 
    Setting mSetting;
 
    @Override
    protected void onMessage(Context context, Intent intent) {
        mSetting = new Setting(context);
 
        if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
 
            String option_push = mSetting.getString(KEY_PUSHCH, "");
 
            if ("true".equals(option_push)) {
                showMessage(context, intent);
            }
        }
    }
 
    @Override
    protected void onError(Context context, String msg) {
        // TODO Auto-generated method stub
        Log.w(TAG, "onError!! " + msg);
    }
 
    @Override
    protected void onRegistered(Context context, String regID) {
        // TODO Auto-generated method stub
        if (listener != null) {
            listener.next();
            listener = null;
        }
        mSetting = new Setting(context);
        mSetting.input(KEY_GCM_REGI_ID, regID);
    }
 
    @Override
    protected void onUnregistered(Context context, String regID) {
        // TODO Auto-generated method stub
        Log.w(TAG, "onUnregistered!! " + regID);
    }
 
    public void showToast() {
        Toast.makeText(this, "RegID 등록 완료", Toast.LENGTH_SHORT).show();
    }
 
    private void showMessage(Context context, Intent intent) {
        String title = intent.getStringExtra(KEY_TITLE);
        String msg = intent.getStringExtra(KEY_MSG);
        String section = intent.getStringExtra(KEY_SECTION);
        String category = intent.getStringExtra(KEY_CATEGORY);
        String no = intent.getStringExtra(KEY_NO);
        String fairurl = intent.getStringExtra(KEY_FAIRURL);
 
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Activity.NOTIFICATION_SERVICE);
 
        // // 해당 어플을 실행하는 이벤트를 하고싶을 때 아래 주석을 풀어주세요
        PendingIntent pendingIntent;
 
        String url = "section=" + section + "&category=" + category + "&no="
                + no;
 
        int titleBar = DataManager.getCodeModel(Integer.valueOf(category)).getTitleText();
         
        pendingIntent = PendingIntent.getActivity(
                context,
                0,
                new Intent(context, DetailNewsViewActivity.class)
                        .putExtra(KEY_SUB_URL, url)
                        .putExtra(KEY_SECTION, section)
                        .putExtra(KEY_CATEGORY, category)
                        .putExtra(KEY_TITLEBAR, titleBar)
                        .putExtra(KEY_CHANNEL, true)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
                PendingIntent.FLAG_UPDATE_CURRENT);
 
        Notification notification = new Notification();
        notification.icon = R.drawable.icon;
        notification.when = System.currentTimeMillis();
 
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, title, msg, pendingIntent);
 
        notificationManager.notify(0, notification);
 
        Intent i = new Intent(context, GCMMessageView.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.putExtra(KEY_TITLEBAR, titleBar);
        i.putExtra(KEY_MSG, msg);
        i.putExtra(KEY_SUB_URL, url);
        i.putExtra(KEY_SECTION, section);
        i.putExtra(KEY_CATEGORY, category);
        i.putExtra(KEY_FAIRURL, fairurl);
 
        context.startActivity(i);
 
        {
            Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
 
            // Wake Android Device when notification received
            PowerManager pm = (PowerManager) context
                    .getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock mWakelock = pm.newWakeLock(
                    PowerManager.FULL_WAKE_LOCK
                            | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
            mWakelock.acquire();
 
            Timer timer = new Timer();
            TimerTask task = new TimerTask() {
                public void run() {
                    mWakelock.release();
                }
            };
            vibe.vibrate(1000);
            timer.schedule(task, 5000);
 
        }
 
    }

현재 GCMINTENTSERVICE 소스가 이렇게 되어있는데요. php로 msg section category no 네가지 파라미터를 보내서 이걸 받아서 푸시를 보내고 있는데 노티피케이션 목록에 2개 이상의 푸시메시지가 쌓여있을 때 어떤걸 누르던지 무조건 마지막에 보냈던 위치로 이동이 되네요. 어떻게 해야 할까요?

양꼬양 (2,040 포인트) 님이 2015년 6월 10일 질문

1개의 답변

+1 추천
 
채택된 답변

notificationManager.notify(0, notification);

해당 구문에서 0을 변경하여 주시면 됩니다~!

쉽게 보자면 노티의 인덱스라고 보시이 펴하 실듯 합니다.

해당 소스는 항상 0을 주게 되니 노티가 하나 밖에 생성 될수가 없습니다~!

ThisPlus (46,920 포인트) 님이 2015년 6월 10일 답변
양꼬양님이 2015년 8월 3일 채택됨
아 의견 감사합니다 ㅎㅎ; 아 제가 드린 질문의 요지는 노티가 2개이상 생성 되었을 때 각각 가지고 있는 intent 정보에 section category no 이 세개 정보가 마지막으로 발송된 노티 intent를 가지고 있어서 모두 같은 경로로 이동 하는걸 말씀 드린거에요 ㅎㅎ; A B C 3개의 노티가 있고 이벤트시 페이지 이동 하는것도 각각 다르게 이동하도록 파라미터를 보냈는데 C를 마지막으로 보냈다고 치면 A B C 세 개의 노티가 모두 C 페이지로 이동합니다..; 그것때문에 문제에요 ㅜㅜ
PendingIntent의 flag를 FLAG_UPDATE_CURRENT 에서 FLAG_ONE_SHOT으로 변경해 보세요.
...