2

My app displays all user apps in a ListView, I want to take the user to the screen where they can uninstall that app onclick. However, the code I am using opens the info screen for about 1/4 second and then takes the user back to the app. Where am I wrong??

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);
    }
});

I would like to take the user directly to the message where it asks "are you sure you want to uninstall <appname>.apk?"

Mike
  • 4,550
  • 4
  • 33
  • 47

3 Answers3

2

Please refer below code :

String app_pkg_name = "com.example.app";
int UNINSTALL_REQUEST_CODE = 1;

Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);  
intent.setData(Uri.parse("package:" + app_pkg_name));  
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
startActivityForResult(intent, UNINSTALL_REQUEST_CODE);

For more detail refer install / uninstall APKs programmatically (PackageManager vs Intents)

Community
  • 1
  • 1
Anjali Tripathi
  • 1,477
  • 9
  • 28
0
Uri packageUri = Uri.parse("package:" + packageName);
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(intent);

This will work for Android 4.0 and above. For all versions use Intent.ACTION_DELETE

egfconnor
  • 2,637
  • 1
  • 26
  • 44
0

Are you getting any exception ?

try {
    //Open the specific App Info page:
    Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.setData(Uri.parse("package:" + packageName));
    startActivity(intent);
} catch ( ActivityNotFoundException e ) {
    //e.printStackTrace();

    //Open the generic Apps page:
    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
    startActivity(intent);
}
Mike
  • 4,550
  • 4
  • 33
  • 47
CodingRat
  • 1,934
  • 3
  • 23
  • 43