Android How to - Install APK from URL








Question

We would like to know how to install APK from URL.

Answer

/*from   ww w  .  j a v a 2s  . c om*/
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {

  public static void installApkFileFromUri(Context context, Uri appPath) {
    Intent intent = new Intent();
    intent.setDataAndType(appPath, "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
  }
}