Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24629] Android: Add wakeLock to NotificationManager

GitHub Issuen/a
TypeNew Feature
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-08-28T18:34:14.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.2.0
ComponentsAndroid
Labelsandroid, notification
ReporterMichael Gangolf
AssigneeGary Mathews
Created2017-04-25T18:46:19.000+0000
Updated2018-09-07T01:29:24.000+0000

Description

Add the possibility to add a wakeLock to Titanium.Android.Notification to switch on the screen when a Notification is fired *Example:*
var win = Ti.UI.createWindow({});
var btn = Ti.UI.createButton({
	title: "click"
});
win.add(btn);

btn.addEventListener("click", function() {
	_.delay(function() {
		var intent = Ti.Android.createIntent({
			action: Ti.Android.ACTION_MAIN,
			className: 'com.appcelerator.notificationsample.NotificationsampleActivity',
			packageName: 'com.appcelerator.notificationsample'
		});
		intent.flags |= Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK;
		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 to return to the application.',
			contentIntent: pending,
			wakeLock: 100
		});
		Titanium.Android.NotificationManager.notify(1, notification);
	}, 4000);
});

win.open();
Add permission to tiapp.xml {noformat} http://schemas.android.com/apk/res/android"> {noformat} * start the app * click the button and lock the device * notification will appear and screen turns on It will stay on the wakeLock time (+normal screen on time)

Comments

  1. Michael Gangolf 2017-04-25

    PR: https://github.com/appcelerator/titanium_mobile/pull/8990
  2. Rainer Schleevoigt 2017-04-25

    https://developer.android.com/reference/android/os/PowerManager.html#newWakeLock(int,%20java.lang.String) There is more then one paramter (time). I think wee need more then one options => KrollDict
  3. Michael Gangolf 2017-04-26

    I'll have a look at the parameters. In most cases the default parameter is enough because you would just need to turn the screen on (which is better than the current solution not to do it :-) ). But it might be useful to have the levelAndFlags exposed.
  4. Hans Knöchel 2017-04-26

    This more a Feature than a Bug right? :-) Scheduling for 6.2.0.
  5. Michael Gangolf 2017-04-26

    Yes, it's a new feature. I've changed the parameter and the example is :
       var win = Ti.UI.createWindow({});
       var btn = Ti.UI.createButton({
       	title: "click"
       });
       win.add(btn);
       
       btn.addEventListener("click", function() {
       	_.delay(function() {
       		var intent = Ti.Android.createIntent({
       			action: Ti.Android.ACTION_MAIN,
       			className: 'com.appcelerator.notificationsample.NotificationsampleActivity',
       			packageName: 'com.appcelerator.notificationsample'
       		});
       		intent.flags |= Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK;
       		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 to return to the application.',
       			contentIntent: pending, 
       			wakeLock: {
       				time: 2000,
       				flags: Ti.Android.PARTIAL_WAKE_LOCK | Ti.Android.ON_AFTER_RELEASE
       			}
       		});
       		Titanium.Android.NotificationManager.notify(1, notification);
       	}, 4000);
       });
       
       win.open();
       
  6. Hans Knöchel 2017-08-11

    6_2_X: https://github.com/appcelerator/titanium_mobile/pull/9307
  7. Lokesh Choudhary 2017-08-22

    Failing review. Please see master PR for info.
  8. Lokesh Choudhary 2017-08-24

    FR Passed for master PR. Master PR merged.
  9. Lokesh Choudhary 2017-08-28

    FR Passed for 6.2.0 PR & merged.
  10. Lokesh Choudhary 2017-08-29

    Verified the fix in SDK 6.2.0.v20170828180251 & 7.0.0.v20170828180637. Closing. Studio Ver: 4.9.1.201707200100 OS Ver: 10.12.3 Xcode Ver: Xcode 8.3.3 Appc NPM: 4.2.9 Appc CLI: 6.2.3 Ti CLI Ver: 5.0.14 Alloy Ver: 1.9.13 Node Ver: 6.10.1 Java Ver: 1.8.0_101 Devices: ⇨ google Pixel --- Android 7.1.1 ⇨ google Nexus 5 --- Android 6.0.1 ⇨ Motorola G2 --- Android 4.4.4

JSON Source