Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.util.Enumeration;

import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    private static final String APK_MANIFEST = "AndroidManifest.xml";

    /**
     * To check if the apk file is available to install.
     * 
     * @param apkFilePath the apk file path
     * @return            true if available, otherwise return false
     */
    public static boolean isApkAvailable(String apkFilePath) {
        File apkFile = new File(apkFilePath);
        if (!apkFile.exists()) {
            return false;
        }

        try {
            ZipFile zipFile = new ZipFile(apkFile);
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry zipEntry = entries.nextElement();
                if (APK_MANIFEST.equals(zipEntry.getName())) {
                    zipFile.close();
                    return true;
                }
            }

            zipFile.close();
        } catch (Exception e) {
            return false;
        }

        return false;
    }
}