푸시 알림 앱이 있습니다. 푸시 알림이되면 는 브로드 캐스트 리시버는 추가에 대한 사용자의 클릭이 일정 할 때, 모든 매개 변수를 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에 로그인 할 때, 그것은 인도네시아은 (그것은 싱가포르이어야 함)을 보여줍니다.도와주세요.
감사합니다.
가의 getService() – pskink
의 두 번째 PARAM에 대한 문서를 읽어 @pskink 주셔서 감사합니다 –