8

我有以下异常跟踪。

  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>
4

1 回答 1

4

请参阅 OPPO 的帖子:http: //bbs.coloros.com/thread-174655-3-1.html

以下是帖子的一些翻译: 自动屏幕关闭一段时间后,系统将启动电池管理模块,它将禁止任何应用程序启动。但是有一个错误,它应该强制停止应用程序而不是抛出异常。

从开发人员方面,他们给出了一个解决方案:在启动服务时使用“try catch”。

于 2017-03-21T03:25:31.570 回答