appcelerator - Time based notifications -
i building app needs send time-based notifications user.
i using notification manager module , background services , pushing notifications. working fine long app opened either in background or accessible.
once close app, notifications not coming. how can ensure service running though app closed , keep sending notifications?
start service using titanium.android.startservice example,
app.js
var intent = titanium.android.createserviceintent({ url: 'myservice.js' }); intent.putextra('interval', 10000); // service should run code every 2 seconds. intent.putextra(titanium.android.extra_dont_kill_app, true); titanium.android.startservice(intent);
myservice.js
var intent = ti.android.createintent({ action: ti.android.action_main, classname: 'com.testapp.testappactivity', packagename: 'com.testapp' }); intent.addcategory(ti.android.category_launcher); var pending = titanium.android.creatependingintent({ intent: intent, flags: titanium.android.flag_update_current }); var notification = titanium.android.createnotification({ contenttitle: 'something happened', contenttext: 'click return application.', contentintent: pending }); titanium.android.notificationmanager.notify(1, notification);
also add service tiapp.xml,
<android xmlns:android="http://schemas.android.com/apk/res/android"> <services> <service url="myservice.js" type="interval" /> </services> </android>
Comments
Post a Comment