【发布时间】:2022-10-02 10:05:22
【问题描述】:
在模拟器中,我的应用程序运行良好,但是当我在真正的三星 Galaxy 设备上使用该应用程序时,该应用程序将崩溃。我现在已经调试它并看到这个错误:
2022-04-02 22:41:18.584 16611-16611/? E/USNET: USNET: appName: ch.yourclick.ki 2022-04-02 22:41:19.546 16611-16611/ch.yourclick.ki E/AndroidRuntime: 致命例外: 主进程: ch.yourclick.ki, PID: 16611 java.lang.RuntimeException:无法启动服务 ch.yourclick.ki.services.PicovoiceService@d2ab860 与 Intent { cmp=ch.yourclick.ki/.services.PicovoiceService(有附加功能)}: java.lang.IllegalArgumentException: ch.yourclick.ki: 目标 S+ (版本 31 及更高版本)要求 FLAG_IMMUTABLE 或 创建 PendingIntent 时指定 FLAG_MUTABLE。强烈 考虑使用 FLAG_IMMUTABLE,仅在某些情况下使用 FLAG_MUTABLE 功能取决于 PendingIntent 是可变的,例如如果它 需要与内联回复或气泡一起使用。在 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5110) 在 android.app.ActivityThread.access$2200(ActivityThread.java:310) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319) 在 android.os.Handler.dispatchMessage(Handler.java:106) 在 android.os.Looper.loopOnce(Looper.java:226) 在 android.os.Looper.loop(Looper.java:313) 在 android.app.ActivityThread.main(ActivityThread.java:8663) 在 java.lang.reflect.Method.invoke(Native Method) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) 引起:java.lang.IllegalArgumentException:ch.yourclick.ki: 定位 S+(版本 31 及更高版本)需要满足以下条件之一 FLAG_IMMUTABLE 或 FLAG_MUTABLE 在创建时指定 待定意图。强烈考虑使用FLAG_IMMUTABLE,只使用 FLAG_MUTABLE 如果某些功能依赖于 PendingIntent 是 可变的,例如如果它需要与内联回复或气泡一起使用。 在 android.app.PendingIntent.checkFlags(PendingIntent.java:382) 在 android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465) 在 android.app.PendingIntent.getActivity(PendingIntent.java:451) 在 android.app.PendingIntent.getActivity(PendingIntent.java:415) 在 ch.yourclick.ki.services.PicovoiceService.getNotification(PicovoiceService.java:142) 在 ch.yourclick.ki.services.PicovoiceService.onStartCommand(PicovoiceService.java:127) 在 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092) ... 9 更多
这就是我启动服务的方式:
mDialog.startService(getContext()); // <-- App only crashes when I use this linepublic void startService(Context context) { mServiceIntent = new Intent(context, PicovoiceService.class); mServiceIntent.putExtra(\"keywordFileName\", \"Hey-Ki_de_android_v2_1_0.ppn\"); mServiceIntent.putExtra(\"contextFileName\", \"Ki_de_android_v2_1_0.rhn\"); ContextCompat.startForegroundService(context, mServiceIntent); }在我的应用程序中一切正常,所以只有当我按下按钮启动服务
PicovoiceService.class时应用程序才会崩溃。我的代码有什么问题,为什么它可以在模拟器中运行,但不能在真实设备上运行?
-
您的模拟器正在运行什么 API 级别?
-
@Flash103 它是 API 30。