안녕하십니까!
이 문제는 며칠 동안 도청되어 왔고 해결 방법을 찾지 못했습니다.
나는 티타늄으로 안드로이드에 대한 하나의 스케줄 된 통보를하는 법을 안다.
그러나 예약 된 알림이 둘 이상 필요한 경우 문제가 나타납니다.
두 번째 알림을 시작하려고 했는데도 여전히 일정에있는 첫 번째 알림이 즉시 팝업됩니다.
두 번째 알림은 절대로 실행되지 않았습니다.
Android에서 Titanium을 사용하여 예약 된 알림을 두 개 이상 만드는 방법이 있는지 또는 지금 사용하고있는 것보다 예약 된 알림을 구현하는 데 더 좋은 방법이 있는지 알고 싶습니다.appcelerator 티타늄으로 안드로이드에 복수 예약 안드로이드 알림
읽어 주셔서 감사합니다.
여기에있는 코드를 사용하여 구현합니다.
https://github.com/appcelerator-developer-relations/Forging-Titanium/tree/master/ep-013/notify
이것은 알림 서비스를 만드는 데 사용하는 기능입니다.
var notifyId=0;
var notify=function(message,interval){
var intent = Ti.Android.createServiceIntent({
url : 'NotificationService.js'
});
intent.putExtra('message', message || 'You have a notification!');
intent.putExtra('notifyId',notifyId+'');
notifyId++;
if (interval) {
intent.putExtra('interval', interval);
}
Ti.Android.startService(intent);
}
이것은 내 NotificationService.js 파일의 코드입니다.
var NOTIFICATION_PROPERTY = 'notificationCount';
var service = Ti.Android.currentService;//maybe problem is here
var serviceIntent = service.getIntent();
var serviceMessage = serviceIntent.hasExtra('message') ? serviceIntent.getStringExtra('message') : 'you have a notification!';
var notifyId=serviceIntent.hasExtra('notifyId')?serviceIntent.getStringExtra('notifyId'):'1';
if (serviceIntent.hasExtra('interval') && !Ti.App.Properties.hasProperty('notificationCount')) {
Ti.App.Properties.setInt(NOTIFICATION_PROPERTY,0);
} else{
if (Ti.App.Properties.hasProperty(NOTIFICATION_PROPERTY)) {
Ti.App.Properties.removeProperty(NOTIFICATION_PROPERTY);
}
var activity = Ti.Android.currentActivity;
var intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_MAIN,
className:'com.fishtruck.Activity',
flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP
});
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);
var pending = Ti.Android.createPendingIntent({
activity : activity,
intent : intent,
type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY
});
var notification = Ti.Android.createNotification({
contentIntent : pending,
contentTitle : 'test',
contentText : serviceMessage,
tickerText : serviceMessage,
when : new Date().getTime(),
icon : Ti.App.Android.R.drawable.appicon,
flags : Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS
});
Ti.Android.NotificationManager.notify(parseInt(notifyId), notification);
Ti.Android.stopService(serviceIntent);
}