开发者

error with getting list of apps

开发者 https://www.devze.com 2023-02-20 06:40 出处:网络
I have the following code to get a list of installed apps on the phone but i am getting the following error:

I have the following code to get a list of installed apps on the phone but i am getting the following error:

Type mismatch: cannot convert from element type Object to ResolveInfo" for the list "for (ResolveInfo rInfo : list)" and also "List is a raw type. References to generic type List should be parameterized" for "List list = pm.queryIntentActivities...

public class safety extends Activity {

  开发者_开发问答  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PackageManager pm = this.getPackageManager();

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

        List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list) {
            Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
        }
    }
}

Does anyone know how to solve these errors?


Try this:

public class Safety extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PackageManager pm = this.getPackageManager();

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

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

    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消