Application type:mobile,titanium sdk:3.3.0,titanium studio:3.3.0,device:Asus zenfone 5,platform:android 4.2,OS:Mac OSX
I am using alarm manager for local notifications.If the app is closed notification launches a blank screen with name of the app.
app.js
var alarmModule = require('bencoding.alarmmanager'); var alarmManager = alarmModule.createAlarmManager(); var now = new Date(); var isRunning = Ti.App.Properties.getBool("service_running", false); if (isRunning) { } else { alarmManager.addAlarmService({ service : 'com.codehouse.clubapp.TestserviceService', year : now.getFullYear(), month : now.getMonth(), day : now.getDate(), hour : now.getHours(), minute : now.getMinutes(), repeat : 'daily', requestcode:1001 }); alarmManager.addAlarmService({ service : 'com.codehouse.clubapp.AnnserviceService', year : now.getFullYear(), month : now.getMonth(), day : now.getDate(), hour : now.getHours(), minute : now.getMinutes()+2, repeat : 'daily', requestcode:1002 }); }testservice.js
var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); setNotification(); Ti.Android.stopService(serviceIntent); function setNotification(alarm) { var activity = Ti.Android.currentActivity; var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, //className : 'org.appcelerator.titanium.TiActivity', //flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP, //url : 'app.js', className : 'com.codehouse.clubapp.Clubapp_New VersionActivity', packageName : 'com.codehouse.clubapp' }); intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER); //intent.putExtra('interval', 2000); var pending = Ti.Android.createPendingIntent({ activity : activity, intent : intent, type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY, flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY, }); var notificationOptions = { contentIntent : pending, contentTitle : 'xxxx', contentText : ''hello", tickerText : 'Whats Today Event Notification!', //when : new Date().getTime(), icon : Ti.App.Android.R.drawable.appicon, flags : Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS | Titanium.Android.FLAG_INSISTENT, sound : Titanium.Android.NotificationManager.DEFAULT_SOUND, }; var notification = Ti.Android.createNotification(notificationOptions); Ti.Android.NotificationManager.notify(1, notification); Ti.App.Properties.setBool("service_running", true); }tiapp.xml
<android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest > <application android:debuggable="false" android:hardwareAccelerated="true" android:largeHeap="true"/> <supports-screens android:anyDensity="false"/> <uses-sdk android:maxSdkVersion="21" android:minSdkVersion="11"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses_permission android:name="com.codehouse.clubapp.permission.C2D_MESSAGE" android:protectionLevel="signature"/> <uses-permission android:name="com.codehouse.clubapp.permission.C2D_MESSAGE"/> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.BROADCAST_STICKY"/> <application> <activity> <activity android:alwaysRetainTaskState="true" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/app_name" android:launchMode="singleTop" android:name=".clubapp_New VersionActivity" android:theme="@style/Theme.Titanium"/> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> <action android:name="com.codehouse.clubapp.MESSAGE"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> <activity android:name="com.arellomobile.android.push.PushWebview"/> <activity android:name="com.arellomobile.android.push.MessageActivity"/> <activity android:name="com.arellomobile.android.push.PushHandlerActivity"/> <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.google.android.c2dm.intent.REGISTRATION"/> <category android:name="com.codehouse.clubapp"/> </intent-filter> </receiver> <receiver android:name="bencoding.alarmmanager.AlarmNotificationListener"/> <receiver android:name="bencoding.alarmmanager.AlarmServiceListener"/> <service android:name="com.arellomobile.android.push.PushGCMIntentService"/> <activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/> <service android:name="com.codehouse.clubappapp.testserviceService"/> <service android:name="com.codehouse.clubappapp.annserviceService"/> <service android:exported="false" android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"/> </application> </manifest> <services> <service type="interval" url="testservice.js"/> <service type="interval" url="annservice.js"/> </services> </android>