Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.os.Environment;

public class Main {
    public static boolean hasSdCard() {
        boolean sResult = false;

        String stateString = null;
        try {
            Class c = Class.forName("android.os.SystemProperties");
            Method m[] = c.getDeclaredMethods();

            try {
                try {
                    stateString = (String) m[1].invoke(null, "EXTERNAL_STORAGE_STATE", "unmounted");
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (stateString != null) {
            if (stateString.equals(Environment.MEDIA_MOUNTED)) {
                sResult = true;
            }
        }
        return sResult;
    }
}