本文整理汇总了Java中android.os.Environment.getExternalStorageDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.getExternalStorageDirectory方法的具体用法?Java Environment.getExternalStorageDirectory怎么用?Java Environment.getExternalStorageDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Environment
的用法示例。
在下文中一共展示了Environment.getExternalStorageDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureInitialized
import android.os.Environment; //导入方法依赖的package包/类
/**
* Initialization code that can sometimes take a long time.
*/
private void ensureInitialized() {
if (!mInitialized) {
lock.lock();
try {
if (!mInitialized) {
mInternalPath = Environment.getDataDirectory();
mExternalPath = Environment.getExternalStorageDirectory();
updateStats();
mInitialized = true;
}
} finally {
lock.unlock();
}
}
}
示例2: saveMarkIntoFile
import android.os.Environment; //导入方法依赖的package包/类
private void saveMarkIntoFile(byte[] version) {
if (version!=null){
if (FileUtils.isSdcardExist()) {
String sdPath = Environment.getExternalStorageDirectory() + "/";
String mSavePath = sdPath + Config.DIRECTORY;
FileUtils.createDirFile(mSavePath);
File txtFile = FileUtils.createNewFile(mSavePath + "/" + Config.VERSION_FILE);//创建文件
if (txtFile!=null){
try {
FileOutputStream fos = new FileOutputStream(txtFile);
fos.write(version);
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
示例3: getExternalCacheDir
import android.os.Environment; //导入方法依赖的package包/类
private static File getExternalCacheDir(Context context) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
if (!appCacheDir.exists()) {
if (!appCacheDir.mkdirs()) {
L.w("Unable to create external cache directory");
return null;
}
try {
new File(appCacheDir, ".nomedia").createNewFile();
} catch (IOException e) {
L.i("Can't create \".nomedia\" file in application external cache directory");
}
}
return appCacheDir;
}
示例4: onOptionsItemSelected
import android.os.Environment; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
case R.id.action_save:
new SaveImageTask().execute(null, null, null);
break;
case R.id.action_share:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
File folder = new File(Environment.getExternalStorageDirectory() + "/Blood Type");
file = new File(folder + "/chart.png");
if (!folder.exists()) {
folder.mkdir();
}
try {
if (file.exists()) {
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivityForResult(Intent.createChooser(share, "Share Blood Chart"), 1);
}
else {
new SaveImageTask().execute(null, null, null);
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivityForResult(Intent.createChooser(share, "Share Blood Chart"), 1);
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
示例5: accessPic
import android.os.Environment; //导入方法依赖的package包/类
public void accessPic(){
System.out.println("ACCESSPIC called");
photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
Uri selectedImage = Uri.fromFile(photo);
getContentResolver().notifyChange(selectedImage, null);
ContentResolver cr = getContentResolver();
try {
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
mImageView.setImageBitmap(bitmap);
} catch (Exception e) {
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
.show();
Log.e("Camera", e.toString());
}
}
示例6: getExternalCacheDir
import android.os.Environment; //导入方法依赖的package包/类
private static File getExternalCacheDir(Context context) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
if (!appCacheDir.exists()) {
if (!appCacheDir.mkdirs()) {
Logger.w("Unable to create external cache directory");
return null;
}
try {
new File(appCacheDir, ".nomedia").createNewFile();
} catch (IOException e) {
Logger.i("Can't create \".nomedia\" file in application external cache directory");
}
}
return appCacheDir;
}
示例7: exportDB
import android.os.Environment; //导入方法依赖的package包/类
static Boolean exportDB(Context context) {
unInitializeDb();
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
File currentDB = context.getDatabasePath(DatabaseContract.DATABASE_NAME);
File backupDB = new File(sd, BACKUP_DB_PATH);
try (FileInputStream fis = new FileInputStream(currentDB)) {
try (FileOutputStream fos = new FileOutputStream(backupDB)) {
FileChannel src = fis.getChannel();
FileChannel dst = fos.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
fis.close();
fos.close();
}
}
initializeDb(context);
return true;
}
} catch (Exception e) {
Log.e("GM/exportDb", e.toString());
}
initializeDb(context);
return false;
}
示例8: getFreeDiskSpace
import android.os.Environment; //导入方法依赖的package包/类
/**
* 计算SD卡的剩余空间
* @return 返回-1,说明没有安装sd卡
*/
public static long getFreeDiskSpace() {
String status = Environment.getExternalStorageState();
long freeSpace = 0;
if (status.equals(Environment.MEDIA_MOUNTED)) {
try {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
freeSpace = availableBlocks * blockSize / 1024;
} catch (Exception e) {
e.printStackTrace();
}
} else {
return -1;
}
return (freeSpace);
}
示例9: initialize
import android.os.Environment; //导入方法依赖的package包/类
@Override
public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
Log.v(TAG, "Init");
this.webView = super.webView;
this.cordovaInstance = super.cordova;
this.context = cordovaInstance.getActivity().getApplicationContext();
this.internalStorage = this.context.getFilesDir();
this.externalStorage = new File(Environment.getExternalStorageDirectory() +
File.separator + EXTERNAL_STORAGE_FOLDER);
}
示例10: createBuildsDirectory
import android.os.Environment; //导入方法依赖的package包/类
/**
* Creates builds directory on user's SD card if needed
*
* @return false if the builds dir doesn't exist and couldn't be created,
* true otherwise
*/
public static boolean createBuildsDirectory() {
File root = Environment.getExternalStorageDirectory();
File buildsDir = new File(root, BUILDS_DIR);
if (!buildsDir.exists()) {
return buildsDir.mkdirs();
}
return true;
}
示例11: createAlbumArtDir
import android.os.Environment; //导入方法依赖的package包/类
@NonNull
@SuppressWarnings("ResultOfMethodCallIgnored")
public static File createAlbumArtDir() {
File albumArtDir = new File(Environment.getExternalStorageDirectory(), "/albumthumbs/");
if (!albumArtDir.exists()) {
albumArtDir.mkdirs();
try {
new File(albumArtDir, ".nomedia").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return albumArtDir;
}
示例12: hasSDCard
import android.os.Environment; //导入方法依赖的package包/类
public static boolean hasSDCard() {
File file = null;
if (Environment.getExternalStorageState().equals("mounted")) {
file = Environment.getExternalStorageDirectory();
}
if (file != null) {
return true;
}
return false;
}
示例13: getBooheeDir
import android.os.Environment; //导入方法依赖的package包/类
public static File getBooheeDir() {
if (!hasSdcard()) {
return null;
}
File booheeDir = new File(Environment.getExternalStorageDirectory(), BOOHEE_DIR);
if (booheeDir.exists()) {
return booheeDir;
}
booheeDir.mkdir();
return booheeDir;
}
示例14: convertAudioFile
import android.os.Environment; //导入方法依赖的package包/类
/**
* Function to convert a given audio file to MP3 format
*
* @param fileName - input file name
* @param errorCallback - function called if the file could not be converted
* @param successCallback - function called if the conversion was successful
*/
@ReactMethod
public void convertAudioFile(String fileName,
final Callback errorCallback,
final Callback successCallback) {
File flacFile = new File(Environment.getExternalStorageDirectory(), fileName);
Log.d("Output file location", Environment.getExternalStorageDirectory().toString() + fileName);
IConvertCallback callback = new IConvertCallback() {
@Override
public void onSuccess(File convertedFile) {
// So fast? Love it!
Log.d("rnaac notice", "convert success");
successCallback.invoke("convert success");
}
@Override
public void onFailure(Exception error) {
// Oops! Something went wrong
errorCallback.invoke("convert failure: " + error.toString());
Log.d("rnaac notice", error.toString());
error.printStackTrace();
}
};
AndroidAudioConverter.with(this.getReactApplicationContext())
// Your current audio file
.setFile(flacFile)
// Your desired audio format
.setFormat(AudioFormat.MP3)
// An callback to know when conversion is finished
.setCallback(callback)
// Start conversion
.convert();
}
开发者ID:SovTech,项目名称:ReactNativeAndroidAudioConverter,代码行数:45,代码来源:ReactNativeAndroidAudioConverterModule.java
示例15: getSavePath
import android.os.Environment; //导入方法依赖的package包/类
public static File getSavePath(Context context){
if(isExternalStorageWritable()){
return Environment.getExternalStorageDirectory();
}
return context.getCacheDir();
}