在Android Nougat中使用直接启动的广播接收器(7.0)

时间:2017-01-31 21:55:46

标签: android broadcastreceiver android-7.0-nougat

我正在使用Android 7.0中的新DirectBoot功能,我正在尝试确定手机在重启和直接启动模式后何时仍处于锁定状态。为此,我实现了一个我在Manifest中定义的BroadcastReceiver。

我的理解是,当手机重新启动时,它会在完成启动时但在用户输入其PIN之前发出ACTION_LOCKED_BOOT_COMPLETED广播。当输入PIN并且电话解锁时,发送ACTION_BOOT_COMPLETED广播。如果我将其intent-filter定义为ACTION_BOOT_COMPLETED,我的Receiver工作正常,但是一旦我添加LOCKED_BOOT_COMPLETED,我就会在重新启动手机时收到这样的致命错误消息,说它无法实例化我的接收器:

let valueDictionary:[String:String] = ["type":"work", "value":"updatetest@test.info"]
let fieldDictionary:[String:Any] = ["email":valueDictionary, "title":"r5-d5"]

let updateItemRequest = PKTItemsAPI.requestToUpdateItem(withID: 383626238, fields: fieldDictionary, files: nil, tags: nil)

PKTClient.current().perform(updateItemRequest).onComplete { response, error in
  if error == nil {
    print("Completed update!")
  } else {
    print("Error updating item.")
  }
}

我不确定为什么只有将我的Receiver的intent-filter从BOOT_COMPLETED更改为LOCKED_BOOT_COMPLETED时才会出现此问题。下面是我的Manifest不起作用(但是,如果我将intent-filter更改为BOOT_COMPLETED,应用程序不会崩溃,接收器工作完全正常!):

01-06 07:25:30.917 3872-3872/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             Process: com.example.nougatencryptiontest, PID: 3872
                                             java.lang.RuntimeException: Unable to instantiate receiver com.example.nougatencryptiontest.MyReceiver: java.lang.ClassNotFoundException: Didn't find class "com.example.nougatencryptiontest.MyReceiver" on path: DexPathList[[zip file "/data/app/com.example.nougatencryptiontest-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.nougatencryptiontest-1/lib/arm64, /system/lib64, /vendor/lib64]]
                                                 at android.app.ActivityThread.handleReceiver(ActivityThread.java:3021)
                                                 at android.app.ActivityThread.-wrap18(ActivityThread.java)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                 at android.os.Looper.loop(Looper.java:154)
                                                 at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                              Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.nougatencryptiontest.MyReceiver" on path: DexPathList[[zip file "/data/app/com.example.nougatencryptiontest-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.nougatencryptiontest-1/lib/arm64, /system/lib64, /vendor/lib64]]
                                                 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                 at android.app.ActivityThread.handleReceiver(ActivityThread.java:3016)
                                                 at android.app.ActivityThread.-wrap18(ActivityThread.java) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                 at android.os.Looper.loop(Looper.java:154) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

任何建议或指示都将不胜感激。

0 个答案:

没有答案