gpt4 book ai didi

java - 本地通知导致 SecurityException

转载 作者:行者123 更新时间:2023-11-30 00:24:12 25 4
gpt4 key购买 nike

我做了一个方法,当进度完成加载时发送本地通知,当我构建应用程序时,一切都清楚,没有任何错误/警告,我在发布 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)

最佳答案

正如@Adam S 上面所建议的,这是通过在 manifest 文件中添加一个 VIBRATE 权限来简单解决的

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

关于java - 本地通知导致 SecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45695206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com