我正在尝试获取手机上所有可用发射器的列表。单击列表中的特定启动器应使其成为默认的主屏幕启动器。单击默认电话启动器(三星的TouchWiz Home)时,应用程序停止运行(但返回到之前设置的主屏幕)。我只能打开第三方发射器,但它没有被设置为默认主屏幕,点击主页按钮后它会回到上一个主屏幕。代码如下。是否有任何可能使其工作理想地像一个弹出列表,Android提供选择启动主屏幕并使其默认?有什么帮助吗?谢谢!
public class AppsListActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apps_list);
loadApps();
loadListView();
addClickListener();
}
private PackageManager manager;
private List<AppDetail> apps;
private void loadApps(){
manager = getPackageManager();
apps = new ArrayList<AppDetail>();
Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
for(ResolveInfo ri:availableActivities){
AppDetail app = new AppDetail();
/* public class AppDetail {
CharSequence label;
CharSequence name;
Drawable icon;}*/
app.label = ri.loadLabel(manager);
app.name = ri.activityInfo.packageName;
app.icon = ri.activityInfo.loadIcon(manager);
apps.add(app);
}
}
private ListView list;
private void loadListView(){
list = (ListView)findViewById(R.id.apps_list);
ArrayAdapter<AppDetail> adapter = new ArrayAdapter<AppDetail>(this,R.layout.list_item,apps) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = getLayoutInflater().inflate(R.layout.list_item, null);
}
ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon);
appIcon.setImageDrawable(apps.get(position).icon);
TextView appLabel = (TextView)convertView.findViewById(R.id.item_app_label);
appLabel.setText(apps.get(position).label);
TextView appName = (TextView)convertView.findViewById(R.id.item_app_name);
appName.setText(apps.get(position).name);
return convertView;
}
};
list.setAdapter(adapter); }
private void addClickListener() {
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int pos,long id){
Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());
ComponentName cn = i.getComponent();
i.setClassName(cn.getPackageName(),cn.getClassName());
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.addCategory(Intent.CATEGORY_DEFAULT);
AppsListActivity.this.startActivity(i);
}
});
}
}
答案 0 :(得分:0)
我尝试使用Android的默认设置应用。可以直接启动设置应用程序以选择使用以下代码
Intent i = new Intent(Settings.ACTION_HOME_SETTINGS);
startActivity(i);