當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment.getExternalStorageDirectory方法代碼示例

本文整理匯總了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();
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:StatFsHelper.java

示例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();
                }
            }
        }
    }
}
 
開發者ID:AlpacaNotSheep,項目名稱:hybrid,代碼行數:20,代碼來源:SyncVersion.java

示例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;
}
 
開發者ID:Spencer231,項目名稱:GifImageLoader,代碼行數:17,代碼來源:StorageUtils.java

示例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;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:38,代碼來源:BloodTable.java

示例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());
    }
}
 
開發者ID:rohansapre,項目名稱:cleanhood,代碼行數:21,代碼來源:CreateEventActivity.java

示例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;
}
 
開發者ID:Loofer,項目名稱:Watermark,代碼行數:17,代碼來源:StorageUtils.java

示例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;
    }
 
開發者ID:xRahul,項目名稱:GroupingMessages,代碼行數:32,代碼來源:DatabaseBridge.java

示例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);
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:23,代碼來源:FileUtils.java

示例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);
}
 
開發者ID:kolbasa,項目名稱:cordova-logcat-filelogger,代碼行數:11,代碼來源:LogCatPlugin.java

示例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;
}
 
開發者ID:kiwiandroiddev,項目名稱:starcraft-2-build-player,代碼行數:15,代碼來源:JsonBuildService.java

示例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;
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:15,代碼來源:MusicUtil.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:11,代碼來源:Util.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:12,代碼來源:SDcard.java

示例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();
}
 
開發者ID:ShaunSheep,項目名稱:ScaleSketchPadDemo,代碼行數:7,代碼來源:BitmapUtils.java


注:本文中的android.os.Environment.getExternalStorageDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。