- 调用Android系统“应用程序信息(Application Info)”界面
大致如下:(以下信息来自这位大婶博客:http://blog.youkuaiyun.com/zhengzhiren/article/details/6159750),如果不想细看,直接调到后面,即可有现成的代码0_0。
到了这个页面,就可以做很多的事了,比如打开开机启动等等。
那么如何进入这个页面呢?
我们只要以android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS作为Action;“package:应用程序的包名”作为URI,就可以用startActivity启动应用程序信息界面了。代码如下:
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts(SCHEME, packageName, null);
intent.setData(uri);
startActivity(intent);
但是,在Android 2.3之前的版本,并没有公开相关的接口。
我们可以分别看到Android2.1和Android2.2的应用管理程序(ManageApplications.java)是如何启动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);
}
而对于2.2与2.1常量APP_PKG_NAME的定义并不相同,在2.2中定义为”pkg”,在2.1中定义为”com.android.settings.ApplicationPkgName”
因此,对于2.1及以下版本,我们可以这样调用InstalledAppDetails:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");
i.putExtra("com.android.settings.ApplicationPkgName", packageName);
startActivity(i);
对于2.2,只需替换上面putExtra的第一个参数为”pkg”。
综上,通用的调用“应用程序信息”的代码如下: