Android How to - Install Activity from apk File








Question

We would like to know how to install Activity from apk File.

Answer

//  ww  w .  j ava2 s.  com
import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

public class Main {
  public static void install(Activity activity, File apkFile) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile),
        "application/vnd.android.package-archive");
    activity.startActivity(intent);
  }

}