1

I am developing an Android application. In my application, I am checking for new version of latest apk in MainActivity. If application need to be updated, I just download the apk file from server using Retrofit and then prompt the user to install the downloaded apk file. All the download process done without any issue. But I am having problem with prompting to user. I followed this link.

This is how I prompt in MainActivity

public void promptToInstallDownloadedApk(String path)
    {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)), "application/com.football.waiyanhein.tonightfootballreport");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

When I run the code, it throws this error.

.354 12750-12750/com.football.waiyanhein.tonightfootballreport E/AndroidRuntime: FATAL EXCEPTION: main Process: com.football.waiyanhein.tonightfootballreport, PID: 12750 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/emulated/0/Android/data/com.football.waiyanhein.tonightfootballreport/files/tonight_football_report.apk typ=application/com.football.waiyanhein.tonightfootballreport flg=0x10000000 } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512) at android.app.Activity.startActivityForResult(Activity.java:3917) at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:77) at android.app.Activity.startActivityForResult(Activity.java:3877) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859) at android.app.Activity.startActivity(Activity.java:4200) at android.app.Activity.startActivity(Activity.java:4168) at com.football.waiyanhein.tonightfootballreport.MainActivity.promptToInstallDownloadedApk(MainActivity.java:912) at com.football.waiyanhein.tonightfootballreport.MainActivity.writeApkDownloadResponseBodyToDisk(MainActivity.java:893) at com.football.waiyanhein.tonightfootballreport.MainActivity$15.onResponse(MainActivity.java:850) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 05-14 04:19:18.359 679-1124/system_process W/ActivityManager: Force finishing activity com.football.waiyanhein.tonightfootballreport/.MainActivity 05-14 04:19:18.387 664-664/? E/EGL_emulation: tid 664: eglCreateSyncKHR(1215): error 0x3004 (EGL_BAD_ATTRIBUTE) 05-14 04:19:18.505 679-10967/system_process I/OpenGLRenderer: Initialized EGL, version 1.4

Why can't I prompt? I set "application/com.football.waiyanhein.tonightfootballreport" to promot. That is my package name.

I tried this too, but it is not working.

public void promptToInstallDownloadedApk(String path)
    {
        Intent promptInstall = new Intent(Intent.ACTION_VIEW)
                .setDataAndType(Uri.parse(path),
                        "application/vnd.android.package-archive");
        startActivity(promptInstall);
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
  • it should be `"application/vnd.android.package-archive"` 100% use this, and post the error you got, this is not supposed to be ur package name., may be there is something wrong with the `path` ? – Yazan May 14 '17 at 09:47

1 Answers1

1

The last example should work. I'm using it like this:

File updatedApk = new File(Environment.getExternalStorageDirectory(),
                        "your_file_name");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(updatedApk),
        "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
comrade
  • 4,590
  • 5
  • 33
  • 48