启动某些应用程序的 InstalledAppDetails 会导致强制关闭
我正在开发一个应用程序,其工作是清除浏览器历史记录。作为此过程的一部分,我将用户发送到浏览器的“应用程序详细信息设置”屏幕,以便他们可以按“强制停止”按钮,这将关闭浏览器中当前打开的所有窗口。这是我用来打开浏览器包的应用程序详细信息活动的代码。
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当我这样做时会被解雇,其中捆绑有附加功能。
这是手动启动此活动时日志中的意图行:
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
有人以前遇到过类似的情况吗?对我来说,找出需要捆绑并添加到意图中以便使其在此设备上正确启动的内容的最佳方法是什么?
我找到了 InstalledAppDetails 活动的源代码 可以在这里找到 但我的异常中引用的行是 1: onCreate 之外并且2:空白。
有没有一种方法可以让我监听手动打开此活动时触发的 Intent 并从中解压额外内容,以便我知道它们是什么,从而知道我需要添加到我的 Intent 中?
I am working on an application whose job it is to clear the browser history. As part of this process I send the user to the APPLICATIONS_DETAILS_SETTINGS screen for the browser so they can press the "Force Stop" button, which will close any windows which are currently open in the browser. This is the code that I am using to open up to the app details activity for the browser package.
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);
This works great on many devices. However one of the devices I am testing on this causes a force close with the following log:
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
To dig in to it a bit further I went into settings->Manage Applications->Browser on the device manually and noticed that the Intent that is fired when I do it this way has Extras bundled into it.
This is the Intent line from the Log when this activity is launched manually:
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
This is the Intent Line from when it is launched from my application:
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
Has anyone come across something like this before? What is the best way for me to figure out what it is that I need to Bundle up and add to the Intent in order for it to properly start on this device?
I've located the source code for the InstalledAppDetails activity, it can be found here But the line referred to in my exception is 1: outside of onCreate and 2: blank.
Is there a way that I can listen for the Intent that is fired when this activity is opened manually and unpack the extras from it so that I know what they are, and thus what I need to add to my Intent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会删除
setComponent()
调用。不需要它(假设文档是正确的),并且为不属于您的组件调用setComponent()
很少是一个好主意。仅操作字符串就应将其路由到适当的活动。I'd remove the
setComponent()
call. It should not be needed (assuming the docs are correct), and callingsetComponent()
for a component that is not yours is rarely a good idea. The action string alone should route it to the appropriate activity.