当前位置: 首页>>代码示例>>Java>>正文


Java Context.getExternalFilesDir方法代码示例

本文整理汇总了Java中android.content.Context.getExternalFilesDir方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getExternalFilesDir方法的具体用法?Java Context.getExternalFilesDir怎么用?Java Context.getExternalFilesDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getExternalFilesDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getArtworkDownloadedResized

import android.content.Context; //导入方法依赖的package包/类
/**
 * Return the artwork saved previously DOWNSIZED
 * Retrieve it from sdcard with the name bounded to the albumid
 * Handy for thumbnails
 *
 * @param context
 * @param albumid
 * @return
 */
public static Bitmap getArtworkDownloadedResized(Context context,
                                                 long albumid) throws FileNotFoundException {

    String path = (context
            .getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
            + "/.Thunder_Music/" + Long.toString(albumid) + ".jpg");

    BitmapFactory.Options o2 = new BitmapFactory.Options();

    o2.inSampleSize = 2;
    o2.inDither = false;
    o2.inPreferredConfig = Bitmap.Config.RGB_565;

    Bitmap tmp = BitmapFactory.decodeStream(new FileInputStream(new File(
            path)), null, o2);
    return tmp;
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:27,代码来源:ImageUtils.java

示例2: onClick

import android.content.Context; //导入方法依赖的package包/类
@Override
protected void onClick()
{
    super.onClick();

    Context context = getContext();
    File path = context.getExternalFilesDir(null);
    if (null == path) {
        path = context.getFilesDir();
    }

    LocalResourceSelectDialog dialog = new LocalResourceSelectDialog();
    dialog.setPath(path);
    dialog.setTypeMask(ConstantsUI.FILETYPE_FOLDER);
    dialog.setCanSelectMultiple(false);
    dialog.setOnSelectionListener(this);
    dialog.show(mFragmentManager, ConstantsUI.FRAGMENT_SELECT_RESOURCE);
}
 
开发者ID:nextgis,项目名称:android_nextgis_mobile,代码行数:19,代码来源:SelectMapPathPreference.java

示例3: loadLoginInfoExternalStorage

import android.content.Context; //导入方法依赖的package包/类
/**
 * Read stored username/password
 * @param context
 * @return
 */
public String loadLoginInfoExternalStorage(Context context) {
    if (isExternalStorageReadable()) {
        Log.i( "htbridge", "loadLoginInfoExternalStorage: readable, all ok!");
        Log.i( "htbridge", "getExternalStorageDirectory = " + Environment.getExternalStorageDirectory());
        Log.i( "htbridge", "getExternalStoragePublicDirectory = " + context.getExternalFilesDir(null) );


        String filename = context.getExternalFilesDir(null) + "/credentials.dat";
        File file = new File(context.getExternalFilesDir(null), "/credentials.dat");

        Log.i( "htbridge", "loadLoginInfoExternalStorage: opening for reading " + filename);

        try {
            FileInputStream inputStream = new FileInputStream(file);

            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder sb = new StringBuilder();
            String line = null;

            while ((line = reader.readLine()) != null) {
                Log.i("htbridge", line);
                sb.append(line).append("\n");
            }
            reader.close();
            return sb.toString();

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    } else {
        return "";
    }
}
 
开发者ID:HTBridge,项目名称:pivaa,代码行数:40,代码来源:Authentication.java

示例4: ServerConfigManager

import android.content.Context; //导入方法依赖的package包/类
public ServerConfigManager(Context context) {
    mContext = context;
    mServersPath = new File(context.getFilesDir(), SERVERS_PATH);
    File externalFilesDir = context.getExternalFilesDir(null);
    mFallbackServerLogsPath = new File(context.getFilesDir(), SERVER_LOGS_PATH);
    mServerLogsPath = externalFilesDir != null ? new File(externalFilesDir, SERVER_LOGS_PATH)
            : mFallbackServerLogsPath;
    mServerLogsPath.mkdirs();

    if (externalFilesDir != null && mFallbackServerLogsPath.exists()) {
        migrateServerLogs(mFallbackServerLogsPath, mServerLogsPath);
        mFallbackServerLogsPath.delete();
    }

    loadServers();
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:17,代码来源:ServerConfigManager.java

示例5: getTempImagesDir

import android.content.Context; //导入方法依赖的package包/类
public static File getTempImagesDir(Context context) {
    if (imagesTempDir == null) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            imagesTempDir = context.getExternalFilesDir(TEMP_IMAGES_PATH);
        } else {
            imagesTempDir = context.getCacheDir();
        }
    }

    if (imagesTempDir != null && !imagesTempDir.exists()) {
        imagesTempDir.mkdirs();
    }

    return imagesTempDir;
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:16,代码来源:ImagesDir.java

示例6: defaultFolder

import android.content.Context; //导入方法依赖的package包/类
public static String defaultFolder(Context context) {
    String folder;
    File externalFolder = context.getExternalFilesDir(null);

    if (externalFolder != null && Device.isKitKatApi()) {
        folder = externalFolder.getAbsolutePath();
    } else {
        folder = Environment.getExternalStorageDirectory().getAbsolutePath();
    }
    //folder = mContext.getExternalFilesDir(null).getAbsolutePath();
    //folder = Environment.getExternalStorageDirectory().getAbsolutePath();
    return folder;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:14,代码来源:PreferenceHelper.java

示例7: getIslamicLibraryBaseDirectory

import android.content.Context; //导入方法依赖的package包/类
@Nullable
public static String getIslamicLibraryBaseDirectory(Context context) {
    String basePath = getAppCustomLocation(context);

    if (!isSDCardMounted()) {
        // if our best guess suggests that we won't have access to the data due to the sdcard not
        // being mounted, then set the base path to null for now.
        if (basePath == null ||
                basePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
                (basePath.contains(BuildConfig.APPLICATION_ID) && context.getExternalFilesDir(null) == null)) {
            basePath = null;
        }
    }

    if (basePath != null) {
        if (!basePath.endsWith(File.separator)) {
            basePath += File.separator;
        }
        return basePath + DownloadFileConstants.ISLAMIC_LIBRARY_BASE_DIRECTORY;
    }
    return null;
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:23,代码来源:StorageUtils.java

示例8: extractDatabase

import android.content.Context; //导入方法依赖的package包/类
private static String extractDatabase(Context context) {
    try {
        File external = context.getExternalFilesDir(null);
        File data = Environment.getDataDirectory();
        if (external != null && external.canWrite()) {
            String dataDBPath = "data/" + context.getPackageName() + "/databases/chuck.db";
            String extractDBPath = "chuckdb.temp";
            File dataDB = new File(data, dataDBPath);
            File extractDB = new File(external, extractDBPath);
            if (dataDB.exists()) {
                FileChannel in = new FileInputStream(dataDB).getChannel();
                FileChannel out = new FileOutputStream(extractDB).getChannel();
                out.transferFrom(in, 0, in.size());
                in.close();
                out.close();
                return extractDB.getAbsolutePath();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jgilfelt,项目名称:chuck,代码行数:24,代码来源:SQLiteUtils.java

示例9: retrieveCacheDir

import android.content.Context; //导入方法依赖的package包/类
private void retrieveCacheDir(final Context context) {
	final String tag="retrieveCacheDir - ";
	dirCache = null;
	if (isExternalStorageWritable()){
		final File dir=new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),DIRECTORY_TILES_CACHE);
		if (!dir.exists()) {
			try {
				if (!dir.mkdirs()){
					Log.w(TAG,tag+"Not possible to create directory: "+ dir.getPath());
				} else {
					dirCache=dir;
				}
			} catch (SecurityException e){
				Log.w(TAG,tag+"Not possible to create directory: "+ dir.getPath(),e);
			}
		} else if (dir.getFreeSpace()<MIN_FREE_BYTES){
			Log.w(TAG,tag+"Not enough free space on external files dir. Minimal required: "+MIN_FREE_BYTES+" bytes.");
		} else {
			dirCache=dir;
		}
	}

	if (dirCache==null){
		Log.w(TAG,tag+"No external files directory available, use cache directory.");
		dirCache = context.getCacheDir();
	}
}
 
开发者ID:videgro,项目名称:Ships,代码行数:28,代码来源:HttpCacheTileServer.java

示例10: createImageFile

import android.content.Context; //导入方法依赖的package包/类
/**
 * Creates empty temporary jpg file in Pictures directory
 * @param context context to get appropriate directory
 * @return File which is for jpg content
 * @throws IOException
 */
public static File createImageFile(Context context) throws IOException {
    // Create an image file name
    String timeStamp =
            new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    String imageFileName = timeStamp + "_";
    File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    return File.createTempFile(imageFileName,  /* prefix */
                               ".jpg",         /* suffix */
                               storageDir      /* directory */);
}
 
开发者ID:earring,项目名称:selimg,代码行数:17,代码来源:FileUtils.java

示例11: initDatabase

import android.content.Context; //导入方法依赖的package包/类
public static SQLiteDatabase initDatabase(Context context) {

        File dbFile = new File(context.getExternalFilesDir("DB") + File.separator + "database.sqlite");
        SQLiteDatabase ret = SQLiteDatabase.openOrCreateDatabase(dbFile, null);

        System.out.println(">> create table");
        ret.execSQL("CREATE TABLE IF NOT EXISTS BANANA (ID INTEGER PRIMARY KEY, NAME TEXT)");

        System.out.println(">> inserts");
        ContentValues vals = new ContentValues(2);
        vals.put("ID", 1);
        vals.put("NAME", "Klaus :-)");
        ret.insert("BANANA", null, vals);

        ContentValues vals2 = new ContentValues(2);
        vals2.put("ID", 2);
        vals2.put("NAME", "jU9's B-)");
        ret.insert("BANANA", null, vals2);

        System.out.println(">> query");
        Cursor c = ret.query("BANANA", new String[]{"ID", "NAME"}, "ID = ?", new String[]{"1"}, null, null, "ID");
        c.moveToFirst();
        System.out.println(">> query result ID: " + c.getString(0) + " NAME: " + c.getString(1));
//        c.moveToNext();
//        System.out.println(">> query result ID: " + c.getString(0) + " NAME: " + c.getString(1));


        return ret;
    }
 
开发者ID:sovteam,项目名称:buddybox,代码行数:30,代码来源:Database.java

示例12: createImageFile

import android.content.Context; //导入方法依赖的package包/类
public static File createImageFile(final Context context) throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

    return File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );
}
 
开发者ID:humaniq,项目名称:humaniq-android,代码行数:13,代码来源:ImageTool.java

示例13: createImageFile

import android.content.Context; //导入方法依赖的package包/类
/**
 * Faz a criação do arquivo de imagem
 */
public static File createImageFile(Context context) throws IOException {

    // Cria uma imagem com o nome
    String imageFileName = "photicker";
    File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefixo */
            ".jpg",         /* suffixo */
            storageDir      /* diretório */
    );
    // Retorna imagem criada
    return image;
}
 
开发者ID:Eduardo8609,项目名称:PhotoApp,代码行数:17,代码来源:ImageUtil.java

示例14: a

import android.content.Context; //导入方法依赖的package包/类
public static File a(boolean z) {
    File file = null;
    Context c = hn.a().c();
    if (z && "mounted".equals(Environment.getExternalStorageState()) && (VERSION.SDK_INT >= 19 || c.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == 0)) {
        file = c.getExternalFilesDir(null);
    }
    if (file == null) {
        return c.getFilesDir();
    }
    return file;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:jm.java

示例15: defaultFolder

import android.content.Context; //导入方法依赖的package包/类
public static String defaultFolder(Context context) {
    String folder;
    File externalFolder = context.getExternalFilesDir(null);

    if (externalFolder != null && Device.isKitKatApi()) {
        folder = externalFolder.getAbsolutePath();
    } else {
        folder = Environment.getExternalStorageDirectory().getAbsolutePath();
    }
    //folder = context.getExternalFilesDir(null).getAbsolutePath();
    //folder = Environment.getExternalStorageDirectory().getAbsolutePath();
    return folder;
}
 
开发者ID:ujjwalagrawal17,项目名称:CodeCompilerApp,代码行数:14,代码来源:PreferenceHelper.java


注:本文中的android.content.Context.getExternalFilesDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。