【发布时间】:2010-12-12 12:06:32
【问题描述】:
是否可以从另一个应用程序启动“应用程序信息”屏幕(即Menu→Settings→Applications→Manage Applications→选择任何应用程序)?
【问题讨论】:
-
有没有办法打开特定应用的DATA USAGE详细信息?
标签: android
是否可以从另一个应用程序启动“应用程序信息”屏幕(即Menu→Settings→Applications→Manage Applications→选择任何应用程序)?
【问题讨论】:
标签: android
在 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);
}
【讨论】:
从 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);
}
【讨论】:
当用户过去拒绝权限请求并在权限请求系统对话框中选择“不再询问”选项时,我使用 Paolo 解决方案打开 SDK 23+ 中的应用程序详细信息设置。
但在这种情况下,我直接使用了getPackageName() 方法。
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
【讨论】:
老问题,改进答案:
/**
* <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;
}
【讨论】:
在 Android 2.3 中,您可以在 ACTION_APPLICATION_DETAILS_SETTINGS Intent 上使用 startActivity() 和适当的 Uri,以调出应用的“管理”屏幕。但是,这对于 Android 2.3 来说是新的——我不知道在以前的 Android 版本中有什么方法可以做到这一点。
【讨论】:
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/意图(过滤器),因此将来可能会发生变化。
【讨论】: