开发者

NotificationManager.notify() fails with SecurityException

When does NotificationManager.notify() require WAKE_LOCK permission on Android 2.2?

I received following stack trace from one user:

java.lang.SecurityException: Neither user ***** nor current process has android.permission.WAKE_LOCK.
  at android.os.Parcel.readException(Parcel.java:1247)
  at android.os.Parcel.readException(Parcel.java:1235)
  at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
  at android.app.NotificationManager.notify(NotificationManager.java:118)
  at android.app.NotificationManager.notify(NotificationManager.java:94)
  ...

UPDATE Calling code in Scala:

  notification = new Notification(android.R.drawable.stat_notify_sync,
    "%s %s".format(statusTitle, finishedStatus), 0)
  notification.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL
  notification.setLatestEventInfo(SyncService.this, statusTitle, finishedStatus,
    PendingIntent.getActivity(SyncService.this, 0, new Intent(SyncService.this, classOf[MainActivity]), 0))
  notificationManager开发者_JAVA百科.notify(NOTIFICATION, notification)


It seems that notification player tries to acquire wake lock when playing sound.

NotificationManagerService source

NotificationPlayer source


It looks as though you are using a service. Perhaps the service runs too long and the phone goes back to sleep before the notification could be sent. I assume you're using the AlarmManager to bring the phone out of sleep to check for updates? If that is the case, you are just going to have to declare the WAKE_LOCK permission like so:

<uses-permission android:name="android.permission.WAKE_LOCK" />

I have run into this issue before, especially when updating from services on the internet. The only solution I have found is to declare the WAKE_LOCK permission.


It seems that it is an issue of some firmwares only, currently the problem has only Meizu.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜