2014-04-01 6 views
2

사용자가 알림 창에서 푸시 알림을 클릭하여 활동/앱을 시작했는지 알 수있는 플래그와 매개 변수가 있는지 알고 싶습니다. . C2DMReceiver.java앱이 푸시 알림을 클릭하여 실행되었는지 알 수있는 방법

에서

내 코드

Context context = getApplicationContext(); 

     PackageManager manager = context.getPackageManager(); 
     Intent notificationIntent = manager 
       .getLaunchIntentForPackage(packageName); 
     notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
     **notificationIntent.putExtra("fromRemote", true);** 

     PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, 
       notificationIntent, 0); 

     NotificationManager notificationManager = (NotificationManager) context 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = new Notification(); 
     notification.icon = R.drawable.icon; 
     notification.tickerText = message; 
     notification.number = badge; 
     notification.when = System.currentTimeMillis(); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     notification.defaults = Notification.DEFAULT_ALL; 
     notification.setLatestEventInfo(context, "Draw Something", message, 
       pendingIntent); 
     notification.contentIntent = pendingIntent; 
     notificationManager.notify(0, notification); 

나는

notificationIntent.putExtra("fromRemote", true); 

설정을 시도했지만 응용 프로그램을 시작할 때 의도에는 엑스트라가 없었다. 내 mainactivity

Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     print("onCreate - bundle has extras"); 
     for (String key: extras.keySet()) 
     { 
      Log.v ("mytag", "MainActivity onCreate key =" + key); 
     } 
    } 
    else { 
     Log.v ("mytag", "onCreate - bundle has NO extras"); 
    } 

내가 얻을 출력의에서 onCreate 함수

내 코드에서 onCreate입니다 - 번들 NO 엑스트라가 없습니다. 따라서 엑스트라가 통과하지 못합니다.

그래서 다른 방법이 있습니까 ?? iOS에서 매우 쉽습니다.

+0

그냥 서버에 뭔가를 게시 :) – Sadegh

+0

http://stackoverflow.com/questions/1198558/매개 변수 - 보낸 사람 - 알림 - 클릭 투 - 활동 - – Urban

+0

감사합니다 Urban - 이것에 대한 모든 종류의 질문을 검색해 보았습니다 :) - 작동했습니다 – Anand

답변

1

이 페이지를 방문한 사람들이 솔루션을 얻을 수 있도록 답변을 게시하십시오.

응용 프로그램을 시작하기 위해 Intent를 만들 때 putExtra(ID_KEY,id)을 사용해야하고 onCreate() 메서드에서 getIntent().getExtras().getInt(ID_KEY);을 사용하여 전달 된 정수를 검색 할 수 있습니다.

추가 될 수 아무것도, 부울을 통과, 문자열 등

소스 - 당신의`Receiver`가 전화를받을 때 https://stackoverflow.com/a/7358692/3036759

+0

Firebase 알림을 이미 클릭 할 때까지 앱이 호출되지 않는 '알림'메시지를 푸시합니다. 어떤 이드를 설정하지 않는다는 의미입니다. – Baggers

관련 문제