2011-04-04 79 views
5

我正在编写列出系统上安装的应用程序的应用程序。我使用PackageManager和queryIntentActivities()来获取应用程序列表。我可以启动它,卸载它(使用ACTION_DELETE),但我不知道如何显示细节(用户可以强制停止,移动到/从SD卡,看到磁盘空间使用等)?如何在Android上显示已安装应用程序的详细信息?

我尝试了ACTION_VIEW,但它也显示2.1上的卸载对话框(没有检查其他版本)。除了在android-dev邮件列表上没有回答的问题,我也没有发现任何东西。

回答

3

从API级别9(又名Android 2.3)开始,您应该可以使用ACTION_APPLICATION_DETAILS_SETTINGS来达到此目的。在以前的Android版本中无法使用此屏幕。

+0

谢谢,这确实工作2.3。不过,我注意到像Advanced Task Manager这样的应用程序可以在2.2(也可能更低)上实现。所以我认为可以使用这种方式来完成> = 2.3以及对于以前版本的某种形式的黑客攻击。 – wojciechka 2011-04-04 17:38:17

8

解决方案与答案的上方和http://groups.google.com/group/android-developers/browse_thread/thread/1d4607eb370b1fe6/3cd4b85c310fe112?show_docid=3cd4b85c310fe112&pli=1组合:

Intent intent; 

    if (android.os.Build.VERSION.SDK_INT >= 9) { 
     /* on 2.3 and newer, use APPLICATION_DETAILS_SETTINGS with proper URI */ 
     Uri packageURI = Uri.parse("package:" + pkgName); 
     intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", packageURI); 
     ctx.startActivity(intent); 
    } else { 
     /* on older Androids, use trick to show app details */ 
     intent = new Intent(Intent.ACTION_VIEW); 
     intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); 
     intent.putExtra("com.android.settings.ApplicationPkgName", pkgName); 
     intent.putExtra("pkg", pkgName); 
     ctx.startActivity(intent);   
    } 
+0

当我尝试强制运行它时(在2.3上),这个'在旧代码的Androids'代码中给了我一个例外。 '无法找到明确的活动类' – Peterdk 2011-10-24 16:07:57

+0

没关系,在2.2它确实运行。很明显,代码路径在2.3+上不起作用,但在2.2-上起作用。 – Peterdk 2011-10-24 16:12:20

0

试试这个

public static void openAppInfo(Context context, String packageName) 
{ 
    try 
    { 
     //Open the specific App Info page: 
     Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 
     intent.setData(Uri.parse("package:" + packageName)); 
     context.startActivity(intent); 
    } 
    catch (ActivityNotFoundException e) 
    { 
     //Open the generic Apps page: 
     Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); 
     context.startActivity(intent); 
    } 
} 
相关问题