GFl*_*lam 15 java android details android-intent
我正在开发一个应用程序,我用包管理器列出已安装的应用程序.我可以获取项目的包名称,但我想根据包启动详细信息屏幕.因此,例如,如果在列表中选择了Dolphin Browser,您将看到以下图像.我怎样才能做到这一点?
最终解决方案将您的目标设置为Gingerbread API级别9,并将您的min设置为API级别7
final int apiLevel = Build.VERSION.SDK_INT;
Intent intent = new Intent();
if (apiLevel >= 9) {
//TODO get working on gb
//Toast.makeText(SDMove.this, "Gingerbread Not Currently Supported", Toast.LENGTH_LONG).show();
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse("package:" + pli.pkg.packageName)));
} else {
final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
intent.putExtra(appPkgName, pli.pkg.packageName);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
khe*_*ang 11
试试这个:
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:your.package.here")));
Run Code Online (Sandbox Code Playgroud)
并将"package:your.package.here"替换为您要查看的真实包...
khe*_*ang 10
这是一个完整的应用程序,ListActivity
其中列出了所有已安装的应用程序.单击包名称时,将打开应用程序详细信息.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Intent for getting installed apps.
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// Get installed apps
List<ResolveInfo> appList = this.getPackageManager().queryIntentActivities(mainIntent, 0);
// Make new list for package names and fill the list.
List<String> packageNameList = new ArrayList<String>();
for (ResolveInfo resolveInfo : appList) {
packageNameList.add(resolveInfo.activityInfo.packageName);
}
// Set the list adapter.
setListAdapter(new ArrayAdapter<String>(this, R.layout.simple, packageNameList));
}
public void onListItemClick(ListView l, View v, int position, long id)
{
// Get the TextView that was clicked.
TextView view = (TextView)v;
// Get the text from the TextView.
String packageName = (String)view.getText();
// Open AppDetails for the selected package.
showInstalledAppDetails(packageName);
}
public void showInstalledAppDetails(String packageName) {
final int apiLevel = Build.VERSION.SDK_INT;
Intent intent = new Intent();
if (apiLevel >= 9) {
intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
} else {
final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
intent.putExtra(appPkgName, packageName);
}
// Start Activity
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
记得要有main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No apps installed"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
和simple.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
Run Code Online (Sandbox Code Playgroud)
在您的布局文件夹中.希望这工作:)