I would like to implement an on click event which prompts the user to download an APK to update my app to the latest version:
public void f(View view) {
Uri uri = Uri.parse("https://www.example.com/app-release.apk");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
I build the app and deploy it to my phone. I start the app and click on the button. The browser opens. In the address bar I see very briefly the URL of the APK. Then this URL disappears and the browser goes to whatever page I visited most recently before the test. The APK is not downloaded.
I have ensured that the version number of the APK to be installed exceeds the version number of the app in which I test the button click. The URL of the APK is valid, and if I explicitly visit that URL in the browser, the APK installs. I enabled android.permission.INTERNET in the manifest. On the phone I have allowed installation of apps from unknown sources, and in Play Store I turned off scanning of non playstore apps.
Any idea what I'm doing wrong?
Edit #1: I am not trying to implement code within my app to download the APK to local storage. I'm simply trying to launch a browser window pointed at the URL of the APK. I'm attempting something similar to the approach described here:
https://juristr.com/blog/2011/02/coding-update-functionality-for-your/
In that solution, the code to prompt for the download of the APK is:
Intent updateIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://some-public-url/deploy/MyApplication.apk"));
startActivity(updateIntent);
That's what I want to do. But it doesn't begin the download. The URL flashes briefly in the address bar, but then the browser goes back to whatever page it was on before.
Edit #2: If I kick it off using the debugger and the virtual device, the code behaves as I expect. If I install the APK to my physical device, and click on the button there, it malfunctions as I described above. Both the physical device and the virtual one are the Nexus 5.
I have created two versions of the APK, a "version 1" and a "version 2". From within version 1 I would like to trigger a download and install of version 2.