Hi all now i am trying to make more than on background service in android using bencode.alarmmanger:'https://github.com/benbahrenburg/benCoding.AlarmManager' and if i make two background service it alert for the last one i have made and the first doesn't work i don't know why this is my code alloy.js
var alarmModule = require('bencoding.alarmmanager'); var alarmManager = alarmModule.createAlarmManager(); var sound = Titanium.Media.createSound(); var date_2 = new Date(); date_2.setHours(06); date_2.setMinutes(50); date_2.setSeconds(01); var date = new Date(); date.setHours(05); date.setMinutes(10); date.setSeconds(01); var service = alarmManager.addAlarmService({ requestCode : 1, service : 'com.midade.alfSona.TestserviceService', year : date.getFullYear(), month : date.getMonth(), day : date.getDate(), hour : date.getHours(), minute : date.getMinutes(), repeat : 'daily' //You can use the words hourly,daily,weekly,monthly,yearly or you can provide milliseconds. }); var service_2 = alarmManager.addAlarmService({ //requestCode : 2, service : 'com.midade.alfSona.NotficationService', year : date_2.getFullYear(), month : date_2.getMonth(), day : date_2.getDate(), hour : date_2.getHours(), minute : date_2.getMinutes(), repeat : 'daily' //You can use the words hourly,daily,weekly,monthly,yearly or you can provide milliseconds. });testService.js
if(!Ti.App.Properties.hasProperty('notificationCount')) { Ti.App.Properties.setInt('notificationCount', 0); } else { Ti.App.Properties.removeProperty('notificationCount'); var activity = Ti.Android.currentActivity; var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, // you can use className or url to launch the app // className and packageName can be found by looking in the build folder // for example, mine looked like this // build/android/gen/com/appcelerator/test/Test7Activity.java className : 'com.midade.alfSona.AlfsonaActivity', // if you use url, you need to make some changes to your tiapp.xml url : 'app.js', 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 : '?? ??? ????? ??????', contentText : '???? ????', // tickerText : 'This is a test', // "when" will only put the timestamp on the notification and nothing else. // Setting it does not show the notification in the future 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(1, notification); var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); // this will display that custom extra that we added when we created the intent // intent.putExtra('message' , 'This is that little extra'); var teststring = serviceIntent.getStringExtra('message'); Ti.API.info('Extra!: ' + teststring); Ti.Android.stopService(serviceIntent); }notfication.js
if(!Ti.App.Properties.hasProperty('notificationCount')) { Ti.App.Properties.setInt('notificationCount', 0); } else { Ti.App.Properties.removeProperty('notificationCount'); var activity = Ti.Android.currentActivity; var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, // you can use className or url to launch the app // className and packageName can be found by looking in the build folder // for example, mine looked like this // build/android/gen/com/appcelerator/test/Test7Activity.java className : 'com.midade.alfSona.AlfsonaActivity', // if you use url, you need to make some changes to your tiapp.xml url : 'app.js', 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 : 'test', tickerText : 'This is a test', // "when" will only put the timestamp on the notification and nothing else. // Setting it does not show the notification in the future 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(2, notification); var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); // this will display that custom extra that we added when we created the intent // intent.putExtra('message' , 'This is that little extra'); var teststring = serviceIntent.getStringExtra('message'); Ti.API.info('Extra!: ' + teststring); //Ti.Android.stopService(serviceIntent); }tiapp.xml
</ios> <android xmlns:android="http://schemas.android.com/apk/res/android"> <!--manifest> <application android:theme="@style/Theme.NoActionBar"/> <user-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/> </manifest--> <manifest> <supports-screens android:anyDensity="false"/> <application> <receiver android:name="bencoding.alarmmanager.AlarmNotificationListener"/> <receiver android:name="bencoding.alarmmanager.AlarmServiceListener"/> <activity android:alwaysRetainTaskState="true" android:configChanges="keyboardHidden|orientation" android:label="Alfsona" android:launchMode="singleTop" android:name=".AlfsonaActivity" android:theme="@style/Theme.Titanium"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest> <services> <service type="interval" url="notfication.js"/> <service type="interval" url="testservice.js"/> </services> </android>have any one answer for this