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 android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import java.io.File;

public class Main {
    /**
     * @param imgName
     * @return
     */
    public static Bitmap getBitmapFromPath(String imgName) {
        String sExtendSdcardDir = "";
        String sAppRoot = "";

        String sdcardRoot = Environment.getExternalStorageDirectory() == null ? ""
                : Environment.getExternalStorageDirectory().getAbsolutePath();
        Log.d("Tiny", "sdcardRoot --" + sdcardRoot);

        if (sdcardRoot != null) {
            sExtendSdcardDir = sdcardRoot;
            sAppRoot = sExtendSdcardDir.concat("/TINY");
        }

        String sCache = sAppRoot.concat("/cache");

        File file = new File(sCache);
        if (!file.exists()) {
            file.mkdirs();
        }
        Log.d("Tiny", "file path --" + file.getAbsolutePath());

        File image = new File(file.getAbsolutePath(), imgName);
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
        return bitmap;
    }
}