在我的项目中,我可以通过以下代码获取所有已安装应用程序的列表:
public class ApplicationFilterActivity extends Activity implements
OnItemClickListener {
ListView appfilter;
SharedPreferences preferences;
public static String filenames = "RotateData";
PackageManager pck;
ArrayList<Applications> results = new ArrayList<Applications>();
ArrayList<String> gotPackagename = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
appfilter = (ListView) findViewById(R.id.lvApp);
preferences = getSharedPreferences(filenames, 0);
PackageManager packageManager = this.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
results.add(new Applications(pk.applicationInfo
.loadIcon(packageManager), ""
+ pk.applicationInfo.loadLabel(packageManager)));
Log.i("AppName", "" + pk.applicationInfo.packageName);
gotPackagename.add(pk.applicationInfo.packageName);
}
appfilter.setAdapter(new Customarrayadapter(this, results));
appfilter.setOnItemClickListener(this);
}
}
但现在我想过滤列表将只显示游戏,这可能吗?