Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Environment;

import android.text.TextUtils;
import java.io.*;

public class Main {

    public static String getRootByApi() {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            File file = Environment.getExternalStorageDirectory();
            if (file == null)
                return null;
            String path = file.getAbsolutePath();
            if (isValidRoot(path))
                return path;
        }
        return null;
    }

    public static boolean isValidRoot(String root) {
        if (TextUtils.isEmpty(root))
            return false;
        File rootFile = new File(root);
        return rootFile.exists() && rootFile.canRead() && rootFile.canWrite();
    }
}