I am developing a small application which displays the installed application as a list in a spinner. Only the application name is displayed as spinner values. Whenever I select an application from spinner I need to retrieve the UID of the selected application. How can I implement the function?
The following is my code for getting the application name from the spinner
appspinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int app_pos, long app_id) {
// TODO Auto-generated method stub
String app_selected=parent.getItemAtPosition(app_pos).toString();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
return;
}
});
The installed application is stored in a list using the PackageManager class and using PackageInfo class I am getting the name of the application.
You will need to use
PackageManagerto get the package information about whatever app you select in the list. I haven’t done this with aSpinnerbut i’m sure it should work the same as it did in myListView.You might want to see how
packageNamereturns thepackageNameso you can try to match it with whatever was selected.hope this points you in the right direction and helps you out. Good Luck.