Onitemclicklistener That Passes The Package Name Of The App Selected To A Method... Help
UPDATE: Now looking for Package Name as opposed to PID I have an app that diplays a listview of all the installed apps on the device. I want to create an OnItemClickListener that p
Solution 1:
You can retrieve the package name for the activityInfo
member of the ResolveInfo
instance whose item you just clicked on:
lv.setOnItemClickListener(newAdapterView.OnItemClickListener()
{
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id)
{
finalStringpackageName= list.get(position).activityInfo.packageName;
Log.i("PACKAGE", packageName);
//TODO: Pass this packageName to a method
}
});
Solution 2:
It is fundamentally wrong to try to associate pids with apps. One app can run in multiple pids, one pid can run multiple apps. Whatever you are actually trying to do (you don't say so it is hard to give useful help), this is not the way.
Solution 3:
You might have more than one PID in the application. Take a look at the ActivityManager documentation. http://developer.android.com/reference/android/app/ActivityManager.html
Use this as a base:
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> activities = am.getRunningAppProcesses();
for (int i=0; i< activities.size(); i++)
Log.d ("PID INFO", "Activity " + i + " - PID: " + activities.get(i).pid);
}
And, BTW, don't post so much code next time. It is not relevant for your question :)
Post a Comment for "Onitemclicklistener That Passes The Package Name Of The App Selected To A Method... Help"