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

푸시 notification 클릭시 앱실행 문제..

0 추천
안녕하세요 ^^

GCM으로 notification 받는데 까지 성공했는데 클릭시 원래 앱이 실행되야되는데 이게 에뮬에서는 정상적으로 돌아가는데 실제 폰에서는 작동이 안됩니다.(받는것까진됩니다) 원래 폰에서도 됬는데 기능을 추가하려고 코드를 자꾸 추가하다보니 어느샌가 이게 안되더라고요;(에뮬에선 여전히 됩니다;;) 대체 왜그런건가요?? 아래는 코드입니다

 

브로드캐스트리시버 액티비티

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    public static boolean bAppRunned = false;

    @Override
    public void onReceive(Context context, Intent intent) {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));

        setResultCode(Activity.RESULT_OK);

        if (bAppRunned) {

 

        } else {

            Intent intent_ = new Intent(context, PopupActivity.class);
            intent_.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);   // 이거 안해주면 안됨
            context.startActivity(intent_);

        }

    }

}

 

GcmIntentService 액티비티

 

public class GcmIntentService  extends IntentService {

    public static final String TAG = "icelancer";
    public static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;

 

    public GcmIntentService() {
//        Used to name the worker thread, important only for debugging.
        super("GcmIntentService");

 

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        // The getMessageType() intent parameter must be the intent you received
        // in your BroadcastReceiver.

        String messageType = gcm.getMessageType(intent);

 

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.
                    MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // This loop represents the service doing some work.
                for (int i=0; i<5; i++) {
                    Log.i(TAG, "Working... " + (i + 1)
                            + "/5 @ " + SystemClock.elapsedRealtime());
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ignored) {
                    }
                }

                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotification ( extras.getString("msg"));
                Log.i(TAG, "Received: " + extras.toString());

 

            }
        }
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);

 

 

    }

    // Put the message into a notification and post it.
    // This is just one simple example of what you might choose to do with
    // a GCM message.
    private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.gcm)
                        .setContentTitle("본재팬")
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(msg))
                        .setContentText(msg)
                        .setVibrate(new long[]{0, 500});

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    }

 

 

 

}
껄껄앱 (1,910 포인트) 님이 2016년 2월 23일 질문
혹시 이 문제 해결하셨나요???????
저도 같은 문제 인데 해결이 안되서요.. 노트2 킷캣 버전 사용중입니다.

1개의 답변

0 추천
setflags 에 Intent.FLAG_ACTIVITY_CLEAR_TOP <--이것도 한번 추가해보시겠어여? 코드만봐서는 정확히 모르겠네영 ㅠ
sadeva (21,550 포인트) 님이 2016년 2월 23일 답변
안되네요 ㅠㅠ 코드를 싹다 갈아엎어야겠어요 흑;
...