Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import android.text.TextUtils;

import java.io.File;

public class Main {

    public static void installApk(Context context, File file) {
        if (context != null && isFileExists(file)) {
            Uri uri = Uri.fromFile(new File(file.getAbsolutePath()));
            Intent installIntent = new Intent();
            installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            installIntent.setAction(Intent.ACTION_VIEW);
            String type = "application/vnd.android.package-archive";
            installIntent.putExtra("loadapk", "loadapk");
            installIntent.setDataAndType(uri, type);
            context.startActivity(installIntent);
        }
    }

    public static boolean isFileExists(File file) {
        return file != null && file.isFile() && file.exists();
    }

    public static boolean isFileExists(String filePath) {
        if (!TextUtils.isEmpty(filePath)) {
            File file = new File(filePath);
            return isFileExists(file);
        } else {
            return false;
        }
    }
}