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


Java Environment.getExternalStoragePublicDirectory方法代碼示例

本文整理匯總了Java中android.os.Environment.getExternalStoragePublicDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.getExternalStoragePublicDirectory方法的具體用法?Java Environment.getExternalStoragePublicDirectory怎麽用?Java Environment.getExternalStoragePublicDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.Environment的用法示例。


在下文中一共展示了Environment.getExternalStoragePublicDirectory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.os.Environment; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    pkg = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), Constants.UPDATE_PKG_FILE_NAME);
    if (!pkg.exists()) {
        Context context = getApplicationContext();
        CharSequence text = "Software is up to date.";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
        finish();
    }
    setContentView(R.layout.activity_prompt_update);
    btnUpdate = (Button) findViewById(R.id.update_btn);
    btnUpdate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            doUpdate();
        }
    });
}
 
開發者ID:adonespitogo,項目名稱:AdoBot,代碼行數:22,代碼來源:UpdateActivity.java

示例2: startRecordingVideo

import android.os.Environment; //導入方法依賴的package包/類
public void startRecordingVideo() {
    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        File storageDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DCIM), "Camera");
        videoFile = new File(storageDir, "Commons_" + timeStamp + ".mp4");

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            videoUri = FileProvider.getUriForFile(MainActivity.this,
                    BuildConfig.APPLICATION_ID + ".provider",
                    videoFile);
        } else {
            videoUri = Uri.fromFile(videoFile);
        }

        intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent, VIDEO_CAPTURE);
    } else {
        Toast.makeText(this, R.string.no_camera_on_device, Toast.LENGTH_LONG).show();
    }
}
 
開發者ID:CommonsLab,項目名稱:CommonsLab,代碼行數:25,代碼來源:MainActivity.java

示例3: createImageFile

import android.os.Environment; //導入方法依賴的package包/類
/**
 * For images captured from the camera, we need to create a File first to tell the camera
 * where to store the image.
 *
 * @return the File created for the image to be store under.
 */
private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File imageFile = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    selectedImageUri = Uri.fromFile(imageFile);
    return imageFile;
}
 
開發者ID:weimin96,項目名稱:shareNote,代碼行數:22,代碼來源:BottomSheetImagePicker.java

示例4: getFile

import android.os.Environment; //導入方法依賴的package包/類
public static String getFile() {
    File folder = Environment.getExternalStoragePublicDirectory("/");
    if (!folder.exists()) {
        folder.mkdir();
    }

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    //String imageFileName = "image"+ timeStamp + "_";
    String imageFileName = "Temp_Image";
    File image_file = null;

    try {
        image_file = File.createTempFile(imageFileName, ".jpg", folder);
    } catch (IOException e) {
        e.printStackTrace();
    }


    return image_file.getAbsolutePath();
}
 
開發者ID:dazcode,項目名稱:smart-device-cloud,代碼行數:21,代碼來源:Utilities.java

示例5: cameraIntent

import android.os.Environment; //導入方法依賴的package包/類
private void cameraIntent() throws IOException
{
    if (checkPermissions()){

        final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/";
        File newdir = new File(dir);
        newdir.mkdirs();
        String file = dir+"photo.jpg";
        File newfile = new File(file);
        try {
            newfile.createNewFile();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        mCurrentPhotoPath = Uri.fromFile(newfile);

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoPath);
        startActivityForResult(takePictureIntent, REQUEST_CAMERA);
    }
}
 
開發者ID:AppHero2,項目名稱:Raffler-Android,代碼行數:25,代碼來源:ChatActivity.java

示例6: compress

import android.os.Environment; //導入方法依賴的package包/類
private Exception compress(Bitmap bitmap) {
    File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    if (!outDir.exists()) {
        outDir.mkdirs();
    }
    File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");
    mFileOutputPath = outFile.getAbsolutePath();
    try {
        FileOutputStream fileOutputStream = new FileOutputStream(outFile);
        bitmap.compress(compressFormat, compressQuality, fileOutputStream);
        bitmap.recycle();
        fileOutputStream.flush();
        fileOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
        return e;
    }
    return null;
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:20,代碼來源:BitmapCompressUtil.java

示例7: createImageFile

import android.os.Environment; //導入方法依賴的package包/類
private File createImageFile(boolean privateStorage) throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = privateStorage ? getExternalFilesDir(Environment.DIRECTORY_PICTURES)
            : Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}
 
開發者ID:gejiaheng,項目名稱:TakingPhotosSimply,代碼行數:17,代碼來源:MainActivity.java

示例8: FileToSD

import android.os.Environment; //導入方法依賴的package包/類
public FileToSD(Context context,String inputPath,String outputPath,String versionName) throws IOException
{
	this.context = context;
	
	File outFile = new File(Environment.getExternalStoragePublicDirectory("JYShare"),outputPath);
	InputStream is = new FileInputStream(inputPath);
	FileOutputStream fos = new FileOutputStream(outFile+"_"+versionName+".apk");
	byte[] Buff = new byte[1024];
	
	int fileSize = 0;
	int ReadCount = 0;
	while((ReadCount = is.read(Buff))!=-1)
	{
		fileSize += ReadCount;
		fos.write(Buff, 0, ReadCount);
	}
	is.close();
}
 
開發者ID:ZH-LYH,項目名稱:JYShare,代碼行數:19,代碼來源:FileToSD.java

示例9: saveImageFile

import android.os.Environment; //導入方法依賴的package包/類
private void saveImageFile(Bitmap bitmap) {
    String timeStamp = new SimpleDateFormat(FILE_NAME_TIME_FORMAT,
            Locale.ENGLISH).format(new Date());
    if (bitmap != null) {
        String imageFileName = "ZabbKitGraph_" + timeStamp
                + FILE_NAME_PREFIX;
        File storageDir = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        File picturesDir = new File(storageDir,
                Constants.ZABBKIT_PICTURES_DIR);
        if (!picturesDir.exists()) {
            if (!picturesDir.mkdirs()) {
                return;
            }
        }
        File imageFile = new File(picturesDir, imageFileName);
        saveImage(bitmap, imageFile);
        galleryAddPic(imageFile.getAbsolutePath());
    }
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:21,代碼來源:GraphFragment.java

示例10: createImageFile

import android.os.Environment; //導入方法依賴的package包/類
private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp =
            new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    String imageFileName = String.format("JPEG_%s.jpg", timeStamp);
    File storageDir;
    if (mCaptureStrategy.isPublic) {
        storageDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
    } else {
        storageDir = mContext.get().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    }

    // Avoid joining path components manually
    File tempFile = new File(storageDir, imageFileName);

    // Handle the situation that user's external storage is not ready
    if (!Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(tempFile))) {
        return null;
    }

    return tempFile;
}
 
開發者ID:sathishmscict,項目名稱:Matisse-Image-and-Video-Selector,代碼行數:24,代碼來源:MediaStoreCompat.java

示例11: createImageFile

import android.os.Environment; //導入方法依賴的package包/類
private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DCIM), "Camera");
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}
 
開發者ID:vicky7230,項目名稱:Paprika,代碼行數:17,代碼來源:ImaggaFragment.java

示例12: getAlbumStorageDir

import android.os.Environment; //導入方法依賴的package包/類
@Override
public File getAlbumStorageDir(String albumName) {
	// TODO Auto-generated method stub
	return new File(
	  Environment.getExternalStoragePublicDirectory(
	    Environment.DIRECTORY_PICTURES
	  ), 
	  albumName
	);
}
 
開發者ID:Greenstand,項目名稱:treetracker-android,代碼行數:11,代碼來源:FroyoAlbumDirFactory.java

示例13: testListDownloadsDirectory

import android.os.Environment; //導入方法依賴的package包/類
@Test
public void testListDownloadsDirectory() throws IOException {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    String path = DirectoryRepo.SCHEME + ":" + dir.getAbsolutePath();

    DirectoryRepo repo = new DirectoryRepo(path, false);

    assertNotNull(repo.getBooks());
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:10,代碼來源:DirectoryRepoTest.java

示例14: initData

import android.os.Environment; //導入方法依賴的package包/類
@Override
protected void initData() {
    Intent intent = getIntent();
    packageName = intent.getStringExtra("packageName");
    isMove = intent.getBooleanExtra("isMove", false);
    mHttpDownManager = HttpDownManager.getInstance();
    mHttpDownManager.registerObserver(this);
    mDownUtil = DbDownUtil.getInstance();

    downInfo = mDownUtil.queryDownBy((long) packageName.hashCode());//表示當前任務是否下載過
    if (downInfo == null)
        outFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), packageName + ".apk");
    mPresenter.getAppDetailData(this, packageName);
}
 
開發者ID:guzhigang001,項目名稱:Bailan,代碼行數:15,代碼來源:AppDetailActivity.java

示例15: getLocalBooksDirectory

import android.os.Environment; //導入方法依賴的package包/類
public static File getLocalBooksDirectory() throws ExtStorageUnavailableException {
    if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
        throw new ExtStorageUnavailableException();
    File bloomDir = Environment.getExternalStoragePublicDirectory("Bloom");
    bloomDir.mkdirs();
    return bloomDir;
}
 
開發者ID:BloomBooks,項目名稱:BloomReader,代碼行數:8,代碼來源:BookCollection.java


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