Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;

import android.annotation.SuppressLint;
import android.content.Context;

public class Main {
    /**
     * This method copies a binary from asset directory to working directory.
     * 
     * @param assetPath
     * @param localPath
     * @param context
     * @return true == copied, false == text busy
     */
    private static boolean copyFile(String assetPath, String localPath, Context context) {
        try {
            // detect architecture
            if (isARM())
                assetPath += "_arm";
            else if (isX86())
                assetPath += "_x86";
            else if (isMIPS())
                assetPath += "_mips";
            else
                assetPath += "_arm";

            InputStream binary = context.getAssets().open(assetPath);
            FileOutputStream execute = new FileOutputStream(localPath);

            int read = 0;
            byte[] buffer = new byte[4096];

            while ((read = binary.read(buffer)) > 0) {
                execute.write(buffer, 0, read);
            }

            execute.close();
            binary.close();

            execute = null;
            binary = null;

        } catch (IOException e) {
            return false;
        }
        return true;
    }

    /**
     * is ARM base ?
     * 
     * @return true == yes, false == no
     */
    @SuppressLint("DefaultLocale")
    public static boolean isARM() {
        return (android.os.Build.CPU_ABI.toLowerCase().contains("armeabi"));
    }

    /**
     * is X86 base ?
     * 
     * @return true == yes, false == no
     */
    @SuppressLint("DefaultLocale")
    public static boolean isX86() {
        return (android.os.Build.CPU_ABI.toLowerCase().contains("x86"));
    }

    /**
     * is MIPS base ?
     * 
     * @return true == yes, false == no
     */
    @SuppressLint("DefaultLocale")
    public static boolean isMIPS() {
        return (android.os.Build.CPU_ABI.toLowerCase().contains("mips"));
    }
}