我得到了以下异常追踪。
Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.MyApplication: java.lang.SecurityException: Unable to start service Intent { cmp=com.myapp/.background.MyService }: Unable to launch app com.myapp/10232 for service Intent { cmp=com.myapp/.background.MyService }: user 0 is restricted
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
at android.app.ActivityThread.access$1600(ActivityThread.java:164)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5408)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Caused by java.lang.SecurityException: Unable to start service Intent { cmp=com.myapp/.background.MyService }: Unable to launch app com.myapp/10232 for service Intent { cmp=com.myapp/.background.MyService }: user 0 is restricted
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1728)
at android.app.ContextImpl.startService(ContextImpl.java:1701)
at android.content.ContextWrapper.startService(ContextWrapper.java:516)
at com.myapp.MyApplication.onCreate(MyApplication.java:105)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4685)
at android.app.ActivityThread.access$1600(ActivityThread.java:164)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5408)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
有关此例外的任何线索吗? 看起来,应用是从访客用户安装并尝试访问管理员帐户? 我从OPPO R7 PLUS设备中得到了这个例外。
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp">
<application
android:name=".MyApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<service android:name=".background.MyService" />
</application>
</manifest>
答案 0 :(得分:4)
请参阅OPPO的帖子: http://bbs.coloros.com/thread-174655-3-1.html
以下是帖子的一些翻译: 自动屏幕关闭一段时间后,系统将启动电池管理模块,它将禁止任何应用程序启动。但是有一个错误,它应该强制停止应用程序而不是抛出异常。
从开发者方面来说,他们提供了一个解决方案: 使用&#34;尝试捕获&#34;启动服务时。