本文整理汇总了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;
}
示例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);
}
示例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 "";
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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 */);
}
示例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;
}
示例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 */
);
}
示例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;
}
示例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;
}
示例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;
}