我正在开发一个应用程序,它的工作是清除浏览器历史记录。作为此过程的一部分,我将用户发送到浏览器的APPLICATIONS_DETAILS_SETTINGS屏幕,以便他们按下“强制停止”按钮,该按钮将关闭当前在浏览器中打开的所有窗口。这是我用来打开浏览器包的应用程序详细信息活动的代码。
killBrowserIntent = new Intent();
killBrowserIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); // I have tried "android.intentaction.VIEW" here as well.
killBrowserIntent.setData(Uri.parse("package:com.android.browser"));
ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.applications.InstalledAppDetails");
killBrowserIntent.setComponent(cn);
这在许多设备上都很有效。但是,我正在测试的其中一个设备会导致一个力关闭,并显示以下日志:
09-23 08:21:26.231: INFO/ActivityManager(231): Starting: Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.android.browser cmp=com.android.settings/.applications.InstalledAppDetails } from pid 3497
09-23 08:04:23.833: INFO/ActivityManager(231): Start proc com.android.settings for activity com.android.settings/.applications.InstalledAppDetails: pid=3434 uid=1000 gids={1015, 3002, 3001, 3003, 2001, 1007, 3005}
09-23 08:04:23.843: WARN/InputManagerService(231): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@407e4ec0
09-23 08:04:23.873: INFO/ActivityManager(231): No longer want com.motorola.android.deviceinformationprovider (pid 3124): hidden #21
09-23 08:04:23.893: WARN/dalvikvm(3434): Refusing to reopen boot DEX '/system/framework/com.motorola.android.frameworks.jar'
09-23 08:04:23.903: WARN/dalvikvm(3434): Refusing to reopen boot DEX '/system/framework/com.motorola.android.ptt.common.jar'
09-23 08:04:24.083: WARN/dalvikvm(3434): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): FATAL EXCEPTION: main
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.applications.InstalledAppDetails}: java.lang.NullPointerException
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1702)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1727)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.os.Handler.dispatchMessage(Handler.java:99)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.os.Looper.loop(Looper.java:130)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.ActivityThread.main(ActivityThread.java:3859)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at java.lang.reflect.Method.invoke(Method.java:507)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:647)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at dalvik.system.NativeStart.main(Native Method)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): Caused by: java.lang.NullPointerException
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at com.android.settings.applications.InstalledAppDetails.onCreate(InstalledAppDetails.java:369)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
09-23 08:04:24.083: ERROR/AndroidRuntime(3434): ... 11 more
09-23 08:04:24.083: WARN/ActivityManager(231): Force finishing activity com.android.settings/.applications.InstalledAppDetails
为了深入挖掘它,我进入设置 - >手动管理应用程序 - >浏览器并注意到我这样做时触发的Intent捆绑了Extras。
这是手动启动此活动时日志中的Intent行:
09-23 08:23:59.470: INFO/ActivityManager(231): Starting: Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.android.browser cmp=com.android.settings/.applications.InstalledAppDetails (has extras) } from pid 3540
这是从我的应用程序启动时的意图行:
09-23 08:21:26.231: INFO/ActivityManager(231): Starting: Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.android.browser cmp=com.android.settings/.applications.InstalledAppDetails } from pid 3497
之前有没有人遇到这样的事情?什么是最好的方法让我弄清楚我需要捆绑什么并添加到Intent才能在这个设备上正常启动?
我找到了InstalledAppDetails活动的源代码,it can be found here但我异常中引用的行是1:onCreate之外,2:空白。
有没有办法可以监听手动打开此活动时触发的Intent,并从中解压缩其中的内容以便我知道它们是什么,从而我需要添加到我的Intent中?
答案 0 :(得分:0)
我将移除setComponent()
电话。它不应该被需要(假设文档是正确的),并且为不属于你的组件调用setComponent()
很少是个好主意。单独的操作字符串应该将其路由到适当的活动。