Skip to content

Instantly share code, notes, and snippets.

@Amimul100
Last active August 29, 2015 14:04
Show Gist options
  • Save Amimul100/d34d4821b3556f5ae0cc to your computer and use it in GitHub Desktop.
Save Amimul100/d34d4821b3556f5ae0cc to your computer and use it in GitHub Desktop.
Hi, We have tested this issue using "Android notifications using intents" test case and it's working.
h5. TESTING ENVIRONMENT
Mac OS
Ti CLI 3.3.0-rc
Titanium SDK: 3.3.0.RC and 3.2.X.GA
Android Device and Emulator
h5. TEST CODE
h4. app.js
{code}
var win = Titanium.UI.createWindow({
backgroundColor : 'blue'
});
var btn = Ti.UI.createButton({
title : 'Add Notification'
});
btn.addEventListener('click', function(e) {
var now = new Date().getTime();
var delta = new Date( now + (4 * 1000) );
var deltaMS = delta - now;
var intent = Ti.Android.createServiceIntent({
url : 'ExampleService.js'
});
intent.putExtra('interval', deltaMS);
intent.putExtra('message' , 'This is that little extra');
Ti.Android.startService(intent);
});
win.add(btn);
win.open();
{code}
h4. ExampleService.js
{code}
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,
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 : 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();
var teststring = serviceIntent.getStringExtra('message');
Ti.API.info('Extra!: ' + teststring);
Ti.Android.stopService(serviceIntent);
}
{code}
h4. tiapp.xml
{code}
<android xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the activities tag must be added if you want to use the url property to launch your app -->
<activities>
<activity url="app.js">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
</activities>
<!-- the services tag must be added so that our service will run -->
<services>
<service type="interval" url="ExampleService.js"/>
</services>
</android>
{code}
h5. STEPS TO TEST
• Create a new project
• Update "app.js" file with "app.js" code segment given above.
• Create a new file name "ExampleService.js" in the Resource directory of the project.
• Update "ExampleService.js" file with "ExampleService.js" code segment given above.
• Run on Android Device and Emulator
• App runs with showing the splash screen at the beginning.
h5. EXPECTED RESULT
The splash screen should be visible before the app starts.
Thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment