Android launch applications detail page
Here is the way to do it, this is a generic answer using build infos from your app. You have to use FLAG_ACTIVITY_NEW_TASK
and build the right URI
for your app.
// Build intent that displays the App settings screen.
Intent intent = new Intent();
intent.setAction(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package",
BuildConfig.APPLICATION_ID, null);
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
You can use it from a snackbar for example.
Snackbar.make(
findViewById(R.id.activity_layout),
"snackbar text",
Snackbar.LENGTH_INDEFINITE)
.setAction("Settings", new View.OnClickListener() {
@Override
public void onClick(View view) {
// Build intent that displays the App settings screen.
Intent intent = new Intent();
intent.setAction(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package",
BuildConfig.APPLICATION_ID, null);
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
})
.show();
Try this:
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:your.package.here")));
And replace "package:your.package.here" with the real package you want to view...
Here is a fully working app with a ListActivity
that lists all installed apps. When you click a package name, it opens the app details.
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);
}
Remember to have 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>
and 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>
in your layout folder. Hope this works :)
To launch the app info setting for your app.
Uri uri = new Uri.Builder()
.scheme("package")
.opaquePart(getPackageName())
.build();
startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri));