0


Hallo an alle!
Dieses Problem wird seit Tagen abgehört und ich kann keine Lösung finden.
Ich weiß, wie man eine einzige geplante Benachrichtigung auf Android mit Titanium macht.
Wenn jedoch mehr als eine geplante Benachrichtigung erforderlich ist, wird das Problem angezeigt.
Als ich versuchte, die zweite Benachrichtigung auszulösen, erschien sofort die erste, die noch im Zeitplan war.
Und die zweite Benachrichtigung hat nie gefeuert.
Ich würde wirklich gerne wissen, ob es eine Möglichkeit gibt, mehr als eine geplante Benachrichtigung mit Titanium auf Android zu erstellen, oder eine bessere Methode, geplante Benachrichtigungen zu implementieren, als ich jetzt verwende.mehrere geplante android benachrichtigung auf android mit appcelerator titan

Vielen Dank für das Lesen!

Ich verwende den hier gefundenen Code, um meine Implementierung zu bilden.
https://github.com/appcelerator-developer-relations/Forging-Titanium/tree/master/ep-013/notify

Dies ist die Funktion, die ich verwende, um einen Dienst für eine Benachrichtigung zu erstellen.

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); 

} 

Dies ist der Code in meiner NotificationService.js-Datei.

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); 
} 

Antwort

1

Ich habe ein Ti.Android.stopService(intent); vor Ti.Android.startService(intent);

Beim ersten Start es nichts tut. Auf lange Sicht verhindert es das Starten des ersten.

Ich glaube nicht, dass es eine gute Lösung ist, aber vielleicht funktioniert