我有一个 ListApp 活动,其中列出了所有已安装的应用程序,我在这里尝试做的是当用户从列表中选择一个应用程序时,它应该获取有关所选应用程序的意图/信息,现在当用户单击按钮 1 时,它应该打开之前选择的应用程序(借助之前检索到的意图)。
ListApp 活动:
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()){
case R.id.button1:
//startActivity(app.intent);
//should start app with the help of info received by selecting app from the list
break;
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
//startActivity(app.intent);
//instead of launching app, I would like to get the info about the selected app & use it(start app) when clicking button1
}
应用信息
class ApplicationInfo {
CharSequence title;
Intent intent;
Drawable icon;
boolean filtered;
final void setActivity(ComponentName className, int launchFlags) {
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(className);
intent.setFlags(launchFlags);
}
}
感谢大家 :)