I was having some problem when trying to install the apk programatically and reboot the Android emulator upon installation. I referred to this thread.
Here is my code:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkURI = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".provider", new File(fullPath));
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
Is there any way to install the apk without starting an intent? Because I am executing the method above in doInBackground()
of my AsyncTask. Then in onPostExecute()
, I need to show a fragment stating that the installation is successful.
However, with the code above, upon calling the startActivity()
it just closed all my fragments. Any ideas?
Thanks in advanced!