本文整理匯總了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();
}