我正在處理其清除瀏覽器歷史記錄的應用程序。作爲該過程的一部分,我將用戶發送到瀏覽器的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: [email protected]
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。
這是從日誌的原意時,這一活動是手動啓動:
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:blank之外。
有沒有一種方法可以偵聽在手動打開此活動時觸發的Intent,並從中解開其他附加組件,以便我知道它們是什麼,從而我需要將其添加到我的意圖中?
你能給我們這一行嗎? InstalledAppDetails.java:369 –
我的設備運行的是OS 2.3.4版本,我在這裏找到了源代碼http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-根據第369行的apps/2.3.4_r1/com/android/settings/applications/InstalledAppDetails.java#爲空。它介於onPause()和onAllSizesComputed()之間 – FoamyGuy
是否確定它是相同的版本?代碼和你的應用程序? –