Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-24629

Android: Add wakeLock to NotificationManager

    Details

    • Story Points:
      3
    • Sprint:
      2017 Sprint 17 SDK, 2017 Sprint 18 SDK

      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

      <android xmlns:android="http://schemas.android.com/apk/res/android">
      		<manifest>
      			<uses-permission android:name="android.permission.WAKE_LOCK" />
      		</manifest>
      </android>
      

      • 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)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gmathews Gary Mathews
                Reporter:
                michael Michael Gangolf
                Reviewer:
                Lokesh Choudhary
              • Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code