我开发一个小的应用程序,它显示已安装的应用程序,在微调的列表。只有应用程序名称显示为微调值。每当我从微调选择一个应用程序,我需要找回所选应用程序的UID。我怎样才能实现的功能?
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?
以下是我的code从微调
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;
}
});
使用PackageManager类和使用PackageInfo类我正在应用程序的名称的安装的应用程序被存储在一个列表中。
The installed application is stored in a list using the PackageManager class and using PackageInfo class I am getting the name of the application.
您需要使用 PackageManager
来获取有关的任何应用程序,你在列表中选择包信息。我没有用微调
,但我敢肯定,因为它在做它应该工作一样我的的ListView 。
You will need to use PackageManager
to get the package information about whatever app you select in the list. I haven't done this with a Spinner
but i'm sure it should work the same as it did in my ListView
.
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();
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(
PackageManager.GET_META_DATA);
int UID;
//loop through the list of installed packages and see if the selected
//app is in the list
for (ApplicationInfo packageInfo : packages) {
if(packageInfo.packageName.equals(app_selected)){
//get the UID for the selected app
UID = packageInfo.uid;
break; //found a match, don't need to search anymore
}
}
//Do whatever with the UID
Log.i("Check UID", "UID is: " + UID);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
return;
}
});
您可能想看看的packageName
返回的packageName
,所以你可以尝试与任何选择与之相匹配
You might want to see how packageName
returns the packageName
so you can try to match it with whatever was selected.
希望这点你在正确的方向,并帮助你的。祝您好运。
hope this points you in the right direction and helps you out. Good Luck.
上一篇:什么是最后一个可能的事件我能赶上在用户控制已被证明在.NET中,的WinForms?已被、我能、事件、用户
下一篇:FlowDocument的强制分页符(BreakPageBefore)分页、FlowDocument、BreakPageBefore