PackageManager未显示已安装的动态壁纸

时间:2011-05-18 05:29:06

标签: android

我正在尝试加载设备上所有已安装软件包的列表,但是,当我执行此操作时,任何已安装的动态壁纸都不会显示在列表中...有没有办法解决这个问题?

这是我的代码:

final PackageManager pm = this.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    final ArrayList<ResolveInfo> list =
            (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, 
                    PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : list)
    {
        Log.i(TAG, ": Installed Applications " + rInfo.activityInfo.
                applicationInfo.loadLabel(pm).toString());
    }

    final ArrayAdapter<ResolveInfo> adapter = 
        new ArrayAdapter<ResolveInfo>(this, R.layout.list_item, list)
        {
        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            if (convertView == null)
                convertView = LayoutInflater.from(parent.getContext()).
                    inflate(R.layout.list_item, parent, false);

            final String text = list.get(position).activityInfo.
                applicationInfo.loadLabel(pm).toString();
            ((TextView)convertView.findViewById(R.id.text)).setText(text);

            final Drawable drawable = list.get(position).activityInfo.applicationInfo.loadIcon(pm);
            ((ImageView)convertView.findViewById(R.id.image)).setImageDrawable(drawable);

            return convertView;
        }

        };


    setListAdapter(adapter);
    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

1 个答案:

答案 0 :(得分:6)

试试这个以获得动态壁纸应用程序:

List<ResolveInfo> list = mPackageManager.queryIntentServices(
            new Intent(WallpaperService.SERVICE_INTERFACE),
            PackageManager.GET_META_DATA);

还要记住,他们不需要有活动,他们可以提供服务(他们可能会这样做,因为这就是他们的工作方式)。