2014-11-01 4 views
3

푸시 알림 앱이 있습니다. 푸시 알림이되면 는 브로드 캐스트 리시버는 추가에 대한 사용자의 클릭이 일정 할 때, 모든 매개 변수를 AddToCalendarIntentService을 시작 PendingIntent를 호출Android : NotificationManager 액션에서 IntentService 호출 PendingIntent

mNotificationManager = (NotificationManager) this 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
     Intent intent = new Intent(this, HomeActivity.class); 
     Intent intent = new Intent(this, AddToCalendarIntentService.class); 
     intent.putExtra(JSON_KEY_CLASS_ID, classid); 
     intent.putExtra(JSON_KEY_CLASS_NAME, classname); 
     intent.putExtra(Config.JSON_KEY_DATE, tgl); 
     intent.putExtra(Config.JSON_KEY_TIME_START, timestart); 
     intent.putExtra(Config.JSON_KEY_TIME_END, timeend); 
     intent.putExtra(Config.JSON_KEY_VENUE, venue); 
     Log.d(LOG_TAG, classid + ", " + classname + ", " + venue); 
     PendingIntent contentIntent = PendingIntent.getService(this, 0, 
       intent, 0); 

     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         .setSmallIcon(R.drawable.ic_notif) 
         .setContentTitle("Re: " + classname) 
         .setStyle(new NotificationCompat.BigTextStyle() 
           .bigText(pesan)) 
         .setContentText(pesan) 
         .setDefaults(NotificationCompat.DEFAULT_VIBRATE) 
         .setDefaults(NotificationCompat.DEFAULT_LIGHTS) 
         .setDefaults(NotificationCompat.DEFAULT_SOUND) 
         .addAction(R.drawable.ic_action_add_person, "Add to Calendar", contentIntent) 
         .setAutoCancel(true) 
         .setTicker("Reschedule Class"); 

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

설정 통지에 GCMIntentService를 호출합니다.

public class AddToCalendarIntentService extends IntentService { 

public AddToCalendarIntentService() { 
    super("AddToCalendarIntentService"); 
} 

@Override 
protected void onHandleIntent(Intent intent) { 
    final String JSON_KEY_CLASS_NAME = "classname"; 
    final String JSON_KEY_CLASS_ID = "classid"; 
    Bundle extra = intent.getExtras(); 
    String title = extra.getString(JSON_KEY_CLASS_NAME); 
    String location = extra.getString(Config.JSON_KEY_VENUE); 
    String tgl = extra.getString(Config.JSON_KEY_DATE); 
    String[] tglSplit = tgl.split("-"); 
    int year = Integer.parseInt(tglSplit[0]); 
    int month = Integer.parseInt(tglSplit[1]); 
    int date = Integer.parseInt(tglSplit[2]); 

    String timestart = extra.getString(Config.JSON_KEY_TIME_START); 
    String timeend = extra.getString(Config.JSON_KEY_TIME_END); 
    String[] start = timestart.split(":"); 
    String[] end = timeend.split(":"); 
    int hourStart = Integer.parseInt(start[0]); 
    int minStart = Integer.parseInt(start[1]); 
    int hourEnd = Integer.parseInt(end[0]); 
    int minEnd = Integer.parseInt(end[1]); 
    Log.d("INTENT SERVICE", location); 
    TaskHelper.addToCalendar(this, "Reschedule: " + title, location, year, month-1, date, hourStart, minStart, hourEnd, minEnd); 
    NotificationManager mNotification = (NotificationManager) this 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotification.cancel(1); 
} 
} 

코드는 작동하지만, 내가 다시 다른 통지를 얻고, 달력에 추가하는 경우, AddToCalendarIntentService의 매개 변수는 새를 무시하고, 기존의 매개 변수를 유지합니다. 는 예를 들어, 첫 번째에 위치 인도네시아, GCMIntentService 및 AddToCalendarIntentService 로그 표시 인도네시아 모두 이다. 2 통지에서

는, 위치가 싱가포르 , 그것은 GCMIntentService에서 제대로 보여 주지만, AddToCalendarIntentService에 로그인 할 때, 그것은 인도네시아은 (그것은 싱가포르이어야 함)을 보여줍니다.

도와주세요.

감사합니다.

+0

가의 getService() – pskink

+0

의 두 번째 PARAM에 대한 문서를 읽어 @pskink 주셔서 감사합니다 –

답변

2

시스템을 구분할 필요가있는 보류중인 인 텐트가 두 개 있으면 시스템에서 동일한 PendingIntent를 생각하기 때문입니다.

가장 쉬운 방법은 다른 requestCodes (PendingIntent.getService의 두 번째 매개 변수)를 제공하는 것입니다.

당신은 여기에 대한 자세한 내용을보실 수 있습니다 :

http://developer.android.com/reference/android/app/PendingIntent.html

관련 문제