Java tutorial
//package com.java2s; /* * Copyright (C) 2014 The AppCan Open Source Project. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import android.content.Context; import android.os.Environment; import java.io.File; import java.io.IOException; public class Main { public final static String F_BASE_WGT_PATH = "widgetone/"; public final static String F_APP_PATH = "widgetone/apps/"; public final static String F_WIDGET_PATH = "widgetone/widgets/"; public final static String F_APP_VIDEO = "video/"; public final static String F_APP_PHOTO = "photo/"; public final static String F_APP_AUDIO = "audio/"; public final static String F_APP_MYSPACE = "myspace/"; public static void initWidgetOneFile(Context context, String appId) { String root = null; appId += "/"; if (sdCardIsWork()) { root = getSdCardRootPath(); } else { root = context.getFilesDir().getAbsolutePath() + "/"; } String[] fileDir = { root + F_APP_PATH + appId, root + F_WIDGET_PATH, root + F_APP_PATH + appId + F_APP_VIDEO, root + F_APP_PATH + appId + F_APP_PHOTO, root + F_APP_PATH + appId + F_APP_AUDIO, root + F_APP_PATH + appId + F_APP_MYSPACE }; int size = fileDir.length; for (int i = 0; i < size; i++) { File file = new File(fileDir[i]); if (!file.exists()) { file.mkdirs(); } } String noMediaStr = root + F_BASE_WGT_PATH + ".nomedia"; File noMedia = new File(noMediaStr); if (!noMedia.exists()) { try { noMedia.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } } public static boolean sdCardIsWork() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return true; } return false; } public static String getSdCardRootPath() { return Environment.getExternalStorageDirectory().getAbsolutePath().replace("/mnt", "") + File.separator; } }