标签:
public class InstalledApplicationListActivity extends ListActivity implements OnItemClickListener{
private List<String> mPackages = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager packageManager = getPackageManager();
List<PackageInfo> packageInfos = packageManager
.getInstalledPackages(PackageManager.GET_ACTIVITIES);
for(PackageInfo packageInfo : packageInfos) {
mPackages.add(packageInfo.applicationInfo.loadLabel(packageManager)
+ "\n" + packageInfo.packageName);
}
// ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, textViewResourceId)
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mPackages);
setListAdapter(arrayAdapter);
getListView().setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent intent = new Intent();
intent.putExtra("package_name", mPackages.get(position));
setResult(1, intent);
finish();
}
标签:
原文地址:http://www.cnblogs.com/zhangkefan/p/5043322.html