Reputation: 359
I'm trying to create a notification thats turns on the screen when it happens(same as calls/ sms)
I have this
public void NotifyWithIntent(string title, string text, DateTime time, Type intentTarget) {
int id = 0;
var intent = new Intent(Application.Context, intentTarget);
Android.App.Notification.Builder builder = new Android.App.Notification.Builder(Application.Context).SetContentTitle(title).SetContentText(text).SetSmallIcon(Resource.Drawable.icon2).SetAutoCancel(true).SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
NotificationManager notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
Intent notificationIntent = new Intent(Application.Context, intent.Class);
var pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);
builder.SetContentIntent(pendingIntent);
builder.SetWhen(RepositoryService.TimeMillis(time));
builder.SetPriority((int)NotificationPriority.Max);
builder.SetCategory(NotificationPriorityCategory.Calls.ToString());
Android.App.Notification notification = builder.Build();
notification.Defaults |= NotificationDefaults.Vibrate;
notificationManager?.Notify("", id, notification);
What can i add to get the screen to turn on when the notification occurs ?
/Birger
Upvotes: 0
Views: 1724
Reputation: 74209
Add ACQUIRE_CAUSES_WAKEUP
to your wake lock flags:
var powerManager = (PowerManager)GetSystemService(PowerService);
var wakeLock = powerManager.NewWakeLock(WakeLockFlags.ScreenDim | WakeLockFlags.AcquireCausesWakeup, "StackOverflow");
wakeLock.Acquire();
await Task.Delay(1000);
wakeLock.Release();
Wake lock flag: Turn the screen on when the wake lock is acquired.
Re: PowerManager: ACQUIRE_CAUSES_WAKEUP
Upvotes: 3