Issue description
I am using a simple background service to create a notification. The notification intent has extra data to it, and is then fired. The notification is displayed in the status bar. I pull down the bar and my app is opened/resumed. I try to read the intent data, but it appears as if the app is not resuming and even if I try to get both resume(d) and or the open on the activity I am not able to read any intent data added from the background service.
Please note that even if the service is registered again at next start the notification should still be possible to catch. I have read all things I can get, but I have not found any instruction on how to capture the notification intent data. All guides stop where it has appeared in the status bar, even den android dev ones.
Test outcomes
- Data intent is only retrieved when you get it through android service resource: "app/lib/background_locationservice_android.js"
//DISPLAYS ALERT BOX ("TEST2")
var service = Ti.Android.currentService;
if (service) {
var intent = service.getIntent();
var teststring = intent.getStringExtra("message");
alert(teststring);
service.addEventListener("taskremoved", function() {
Ti.Android.NotificationManager.cancelAll();
Ti.Android.stopService(intent);
});
}
However you can't get intent data either in app/alloy.js or controllers/index.js
Steps to reproduce
Get and run stripped down version on Android device.
Wait until a notification get trigger.
Quit app then click at notification at the statusBar.
Monitor Logs. Depending where was getStringExtra set will be the outcome.
Sample:
https://www.dropbox.com/s/wow58vtprsiktu3/Arkiv_TestCase.zip
Exposed a new method to expose root activity. Only the intent as part of the launched activity will have the extra data. Right now after a window is opened, there is no method to access the root activity. Existing code should work if 'Ti.Android.currentActivity' is called before window is opened. Something like
or use the new API 'getRootActivity' inside 'open' to get the data Something like
PR https://github.com/appcelerator/titanium_mobile/pull/5368
New pull request based on latest master. https://github.com/appcelerator/titanium_mobile/pull/5493 Usage var rootIntent = Ti.App.Android.launchIntent; Ti.API.info('RootIntent message='+rootIntent.getStringExtra('message'));
Test Code
Intent data is successfully captured from a Notification created from Background service, tested using the test code by Vishal Duggal. Intent message is displayed on app screen when clicking the notification in the notification bar. Verified the fix on: Device : Google Nexus 4, Android Version: 4.1.1 SDK: 3.3.0.v20140425191906 CLI version : 3.3.0-dev OS : MAC OSX 10.9.2 Alloy: 1.4.0-dev ACS: 1.0.14 npm:1.3.2 Appcelerator Studio, build: 3.3.0.201404251359 titanium-code-processor: 1.1.1-alpha XCode : 5.1.1