我想获取所有具有 Intent 监听器的应用程序
Intent.CATEGORY_HOME
基本上就是启动器
我有这个代码:
final Intent mainIntent = null;
mainIntent.addCategory(Intent.CATEGORY_HOME);
final List pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
ListView app_list = (ListView) findViewById(R.id.application_list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,pkgAppsList);
app_list.setAdapter(adapter);
这应该返回监听 home 键按下的应用程序
但我只得到一个空指针异常
最佳答案
使用
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
而不是
Intent mainIntent = null;
关于Android Packagemanager queryIntentActivitys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11070340/