install Apk by path - Android android.content.pm

Android examples for android.content.pm:Apk Install

Description

install Apk by path

Demo Code

import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

public class Main {

  /**/*from  w  w w.j  a v  a2s  . c  om*/
   * install an apk bu apkPath
   *
   * @param context
   *          Context
   * @param apkPath
   *          apkPath
   */
  public static final void installApk(Context context, String apkPath) {
    if (TextUtils.isEmpty(apkPath)) {
      return;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive");
    context.startActivity(intent);
  }

}

Related Tutorials