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());
}
}
}
精彩评论