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