如何以编程方式启动android应用程序信息屏幕?

时间:2010-12-12 12:06:32

标签: android

是否可以从其他应用启动“应用信息”屏幕(即MenuSettingsApplicationsManage Applications→选择任何应用)?

6 个答案:

答案 0 :(得分:79)

在2.2及以下版本中,您无法访问公共API。但您仍然可以像 ManageApplications 那样启动 InstalledAppDetails 活动。见here

 // utility method used to start sub activity
 private void startApplicationDetailsActivity() {
     // Create intent to start new activity
     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setClass(this, InstalledAppDetails.class);
     intent.putExtra(APP_PKG_NAME, mCurrentPkgName);
     // start new activity to display extended information
     startActivityForResult(intent, INSTALLED_APP_DETAILS);
 }

结论:您可以像我写的那样启动“应用信息”屏幕:

private static final String SCHEME = "package";

private static final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";

private static final String APP_PKG_NAME_22 = "pkg";

private static final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";

private static final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";

public static void showInstalledAppDetails(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) { // above 2.3
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);
    } else { // below 2.3
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
                : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME,
                APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}

答案 1 :(得分:61)

API级别9 (Android 2.3),您可以使用android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS启动Intent。因此:

packageName = "your.package.name.here"

try {
    //Open the specific App Info page:
    Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.setData(Uri.parse("package:" + packageName));
    startActivity(intent);

} catch ( ActivityNotFoundException e ) {
    //e.printStackTrace();

    //Open the generic Apps page:
    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
    startActivity(intent);

}

答案 2 :(得分:14)

老问题,改进答案:

/**
 * <p>Intent to show an applications details page in (Settings) com.android.settings</p>
 * 
 * @param context       The context associated to the application
 * @param packageName   The package name of the application
 * @return the intent to open the application info screen.
 */
public static Intent newAppDetailsIntent(Context context, String packageName) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("package:" + packageName));
        return intent;
    } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.FROYO) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClassName("com.android.settings",
                "com.android.settings.InstalledAppDetails");
        intent.putExtra("pkg", packageName);
        return intent;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName("com.android.settings",
            "com.android.settings.InstalledAppDetails");
    intent.putExtra("com.android.settings.ApplicationPkgName", packageName);
    return intent;
}

答案 3 :(得分:12)

我使用Paolo解决方案,以便在用户过去拒绝权限请求时打开SDK 23+中的应用程序详细信息设置,并在权限请求系统对话框中选择“不再询问”选项。

但在这种情况下,我直接使用getPackageName()方法。

Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);

答案 4 :(得分:8)

在Android 2.3中,您可以startActivity() Intent使用Uri {{1}},使用正确的{{1}}来启动应用的“管理”屏幕。但是,这是Android 2.3的新功能 - 我不知道在以前版本的Android中有这样做的方法。

答案 5 :(得分:6)

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS));

将带您进入设置/应用程序列表。 如果你想打开一个特定的应用程序,我想在2.2及以下没有办法,所以你需要去(不一定建议,因为非官方的)方式:

final Intent i = new Intent("android.intent.action.VIEW");                
i.setComponent(new ComponentName("com.android.settings","com.android.settings.InstalledAppDetails"));
i.putExtra(...); // need to figure out the correct extra, probably app package name
startActivity(i);

但请注意,建议不要这样做,因为它不是官方API /意图(过滤器),因此可能会在将来发生变化。