是否有可能启动"应用程序信息"屏幕(即Menu
→ Settings
→ Applications
→ Manage Applications
从另一个应用程序→选择任何应用程序)?
Zhe*_*ren 81
在2.2及以下版本中,您无法访问公共API.但您仍然可以像ManageApplications那样启动InstalledAppDetails活动.看到这里
// 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);
}
Run Code Online (Sandbox Code Playgroud)
结论:您可以像我写的那样启动"应用程序信息"屏幕:
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);
}
Run Code Online (Sandbox Code Playgroud)
Pao*_*lli 65
从API Level 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);
}
Run Code Online (Sandbox Code Playgroud)
Jar*_*ler 15
老问题,改进答案:
/**
* <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;
}
Run Code Online (Sandbox Code Playgroud)
Gnz*_*zlt 12
我使用Paolo解决方案,以便在用户过去拒绝权限请求时打开SDK 23+中的应用程序详细信息设置,并在权限请求系统对话框中选择"不再询问"选项.
但在这种情况下,我getPackageName()
直接使用了该方法.
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
在Android 2.3的,你可以使用startActivity()
上,有一个正确的,把你的应用程序的"管理"屏幕.但是,这是Android 2.3的新功能 - 我不知道在以前版本的Android中有这样做的方法.ACTION_APPLICATION_DETAILS_SETTINGS
Intent
Uri
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS));
Run Code Online (Sandbox Code Playgroud)
将带您进入设置/应用程序列表.如果你想打开一个特定的应用程序,我想在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);
Run Code Online (Sandbox Code Playgroud)
但请注意,不建议这样做,因为它不是官方的API /意图(过滤器),因此可能会在将来发生变化.
归档时间: |
|
查看次数: |
37494 次 |
最近记录: |