当前位置: 首页>>代码示例>>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;未经允许,请勿转载。