本地通知导致SecurityException

时间:2017-08-15 14:39:33

标签: java android securityexception android-securityexception

我已经制作了一个方法,当进度完成加载时发送本地通知,当我构建应用程序时,它完全清除,没有任何错误/警告我在使用Google控制台崩溃报告发布后收到此信息

以下是通知方法:

public void notif() {

    final int NOTIFICATION_ID = 1;
    int icon = getIcon();
    String provx = getProv();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext());
    Notification notification = mBuilder
            .setSmallIcon(icon)               
            .setVibrate(new long[]{1000, 1000})
            .setLights(Color.BLUE, 700, 500)
            .setContentTitle("New notification!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(provx))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentText(provx)
            .build();

    NotificationManager nMN = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nMN.notify(NOTIFICATION_ID, notification); //here where I got the error
}

这是崩溃日志:

java.lang.SecurityException: 
   at android.os.Parcel.readException (Parcel.java:1425)
   at android.os.Parcel.readException (Parcel.java:1379)
   at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag (INotificationManager.java:246)
   at android.app.NotificationManager.notify (NotificationManager.java:135)
   at android.app.NotificationManager.notify (NotificationManager.java:111)
   at com.dev.days.myapp.Splash.notif (Splash.java:184)
   at com.dev.days.myapp.Splash$1.run (Splash.java:151)
   at java.lang.Thread.run (Thread.java:856)

1 个答案:

答案 0 :(得分:1)

正如上面提到的@Adam S,只需在VIBRATE文件中添加manifest权限即可解决此问题

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