小编pti*_*tia的帖子

Android获取所有已安装应用的列表

我已使用以下代码获取已安装应用的列表:

public List<ResolveInfo>() {
    PackageManager pm=getPackageManager();
    Intent main=new Intent(Intent.ACTION_MAIN, null);

    main.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);

}
Run Code Online (Sandbox Code Playgroud)

只有一个问题:它只列出具有MAIN活动的应用程序.如何获取所有已安装应用的列表?请注意,我在需要List为ResolveInfo的项目中使用此代码,因此请仅回答返回ResolveInfo列表的代码.

android android-package-managers

3
推荐指数
1
解决办法
1万
查看次数

Android在适配器中更改数据

我将此适配器用于ListView:

Appadapter extends ArrayAdapter<ResolveInfo> 
     private PackageManager pm=null;
     List<ResolveInfo> apps;
     AppAdapter(PackageManager pm, List<ResolveInfo> apps) {
    super(Launchalot.this, R.layout.row, apps);
  this.apps=apps;
  this.pm=pm;
}

@Override
public View getView(int position, View convertView,
                      ViewGroup parent) {
      Log.w(Launchalot.this.getPackageName(),"getView");
  if (convertView==null) {
    convertView=newView(parent);
  }

  bindView(position, convertView);

  return(convertView);
}

private View newView(ViewGroup parent) {
    Log.w(Launchalot.this.getPackageName(),"newView");
  return(getLayoutInflater().inflate(R.layout.row, parent, false));
}


private void bindView(int position, View row) {
  TextView label=(TextView)row.findViewById(R.id.label);
  Log.w(Launchalot.this.getPackageName(),"bindView");
  label.setText(getItem(position).loadLabel(pm));

  ImageView icon=(ImageView)row.findViewById(R.id.icon);

  icon.setImageDrawable(getItem(position).loadIcon(pm));
}
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        setNotifyOnChange(true);}}
Run Code Online (Sandbox Code Playgroud)

我在ListActivity类中使用此代码填充我的视图:

AppAdapter adapter=new AppAdapter(getPackageManager(), getResolveInfoList(0));
setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

现在我已经更改了列表应用程序,我称之为notifyDataSetChanged()但是,我认为没有任何改变.请告诉我一个解决方案.谢谢

android android-listview

2
推荐指数
1
解决办法
1万
查看次数