Reputation: 121
I want to open app info page programmatically.
In which (force stop,uninstall,clear data,clear cache) options are available.I have running process id in list.
Now i am trying to open app info when i clicked on list item. I searched it a lot but could'nt find any topic related to it.
Upvotes: 2
Views: 560
Reputation: 35
getAppNameFromPID(int PID)
to get the package nameshowInstalledAppDetails(String packageName)
to launch the App info/details settings page.And those 2 methods should be created like so:
public void showInstalledAppDetails(String packageName) {
Intent intent = new Intent();
if (Build.VERSION.SDK_INT >= 9) { //this supports all API levels
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);
}
startActivity(intent);
}
private String getAppName(int pID)
{
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List list = am.getRunningAppProcesses();
Iterator i = list.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext()) {
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try {
if(info.pid == pID) //see *NOTE: you might need to compare with info.pkgList
return info.processName;
} catch(Exception e) {
Log.d("getAppName", "Error>> :"+ e.toString());
}
}
return "";
}
Each method seems to work individually, I would think this method would work for your needs.
*NOTE: This will not work if the process name is different from the package name (e.g. it is a service with a different package name). You may need to tweak getAppName
to compare with the strings[] in info.pkgList. Let us know if this works.
Upvotes: 2