my listview displays installed apps having the internet permission, it works fine however, i am trying to enable clicking on list items and take the user to the screen where they can uninstall the app, my code works without any force closes but opens that uninstall screen only 0.25 second and goes back. this is because it is not getting the correct package name. How do i fix this?
public class MainActivity extends Activity {
ArrayList<String> results = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getInstalledApps(this);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, results);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String packageName = results.get(position);
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}
});
}
private ArrayList<String> getInstalledApps(Context context) {
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.v("system app using internet = ", ""+pk.applicationInfo.loadLabel(packageManager));
continue;
}
if (PackageManager.PERMISSION_GRANTED == packageManager .checkPermission(Manifest.permission.INTERNET, pk.packageName) ||
PackageManager.PERMISSION_GRANTED == packageManager .checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, pk.packageName))
results.add("" + pk.applicationInfo.loadLabel(packageManager));
}
Log.v("app using internet = ", results.toString());
return results;
}
}
also i would like to take it directly to the uninstall screen instead of taking it to the app info screen.