title: get package name using PackageManager
body: <p>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?</p>
  
  <pre><code>    public class MainActivity extends Activity {
  
          ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();
  
           @Override
             protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                getInstalledApps(this);
                ArrayAdapter adapter = new ArrayAdapter&lt;String&gt;(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&lt;?&gt; 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&lt;String&gt; getInstalledApps(Context context) {
              PackageManager packageManager = context.getPackageManager();
              List&lt;PackageInfo&gt; applist = packageManager.getInstalledPackages(0);
              Iterator&lt;PackageInfo&gt; it = applist.iterator();
              while (it.hasNext()) {
                  PackageInfo pk = (PackageInfo) it.next();
                  if ((pk.applicationInfo.flags &amp; 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;
          }
      }
  </code></pre>
  
  <p>also i would like to take it directly to the uninstall screen instead of taking it to the app info screen.</p>