Search code examples
androidandroid-intentandroid-activity

How to change target activity of Intent.ACTION_EDIT


I have upgraded my app to allow editing of a text file. I have successfully used the code below

            Intent i = new Intent(Intent.ACTION_EDIT);
            Uri uri = Uri.parse("file:///sdcard/myfile.txt");
            i.setDataAndType(uri, "text/plain");
            startActivity(i);

The first time I ran it, it asked me what editor app to use for the edit and I selected one. The app now always uses the one I selected.
Now I want to try a different editor but it never asks me again.

How can I reset the choice or specify another editing app?

I've searched everywhere but can't find where the editor app is stored.
I've tried uninstalling, rebooting Studio and the device,cleaning and rebuilding with no change to behavior.
BTW, the app was compiled and targeted to SDK level 22, that's why I used the simple 'Uri.parse' instead of a FileProvider. It's an in-house app and I don't care about PlayStore requirements.


Solution

  • Your app isn't doing this. Your app just tells Android to find a suitable app that can handle an Intent with ACTION=EDIT and the mime type of your file. You obviously selected "ALWAYS" when Android asked you what app it should use to open edit that type of file at some point. This set the default app to open. You need to reset that default for the target app (the editor), not your app.

    See https://www.dummies.com/consumer-electronics/tablets/android-tablets/clear-open-default-apps-android-device/ for instructions about how to solve this.