install Apk by Uri - Android App

Android examples for App:APK Install and Uninstall

Description

install Apk by Uri

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {
    public static void installApk(Context context, Uri uri) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // intent.setType("application/vnd.android.package-archive");
        // intent.setData(Uri.fromFile(file));
        intent.setDataAndType(uri,//from w  w w .j  a v  a  2  s  .c  o m
                "application/vnd.android.package-archive");
        context.startActivity(intent);
    }
}

Related Tutorials