本文整理汇总了Java中android.os.Environment类的典型用法代码示例。如果您正苦于以下问题:Java Environment类的具体用法?Java Environment怎么用?Java Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Environment类属于android.os包,在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onContextItemSelected
import android.os.Environment; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case TAKE_PHOTO:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(Environment.getExternalStorageDirectory() + TMP_METACOM_JPG);
Uri uri = FileProvider.getUriForFile(getContext(), AUTHORITY_STRING, f);
takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, PICK_IMAGE_FROM_CAMERA);
}
return true;
case FILE_EXPLORER:
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getString(R.string
.select_file)),
PICK_IMAGE_FROM_EXPLORER);
return true;
default:
return super.onContextItemSelected(item);
}
}
示例2: getDestinationDirectory
import android.os.Environment; //导入依赖的package包/类
private static File getDestinationDirectory(Context context, int destination, boolean running)
throws IOException {
switch (destination) {
case Downloads.Impl.DESTINATION_CACHE_PARTITION:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING:
if (running) {
return context.getFilesDir();
} else {
return context.getCacheDir();
}
case Downloads.Impl.DESTINATION_EXTERNAL:
final File target = new File(
Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS);
if (!target.isDirectory() && target.mkdirs()) {
throw new IOException("unable to create external downloads directory");
}
return target;
default:
throw new IllegalStateException("unexpected destination: " + destination);
}
}
示例3: getAvailableFileSystems
import android.os.Environment; //导入依赖的package包/类
protected HashMap<String, String> getAvailableFileSystems(Activity activity) {
Context context = activity.getApplicationContext();
HashMap<String, String> availableFileSystems = new HashMap<String,String>();
availableFileSystems.put("files", context.getFilesDir().getAbsolutePath());
availableFileSystems.put("documents", new File(context.getFilesDir(), "Documents").getAbsolutePath());
availableFileSystems.put("cache", context.getCacheDir().getAbsolutePath());
availableFileSystems.put("root", "/");
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
try {
availableFileSystems.put("files-external", context.getExternalFilesDir(null).getAbsolutePath());
availableFileSystems.put("sdcard", Environment.getExternalStorageDirectory().getAbsolutePath());
availableFileSystems.put("cache-external", context.getExternalCacheDir().getAbsolutePath());
}
catch(NullPointerException e) {
LOG.d(LOG_TAG, "External storage unavailable, check to see if USB Mass Storage Mode is on");
}
}
return availableFileSystems;
}
示例4: generateWallet
import android.os.Environment; //导入依赖的package包/类
public static Wallet generateWallet(Context context, ECKeyPair ecKeyPair,
final String password)
throws WalletNotGeneratedException
{
try {
final String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair));
final File destDirectory = Environment.getExternalStorageDirectory().getAbsoluteFile();
Log.d(TAG, Environment.getExternalStorageState());
final String fileName = WalletUtils.generateWalletFile(password, ecKeyPair, destDirectory, false);
final String destFilePath = destDirectory + "/" + fileName;
return new Wallet(ecKeyPair, destFilePath, address);
} catch (CipherException | IOException e)
{
e.printStackTrace();
throw new WalletNotGeneratedException();
}
}
示例5: getSDCardInfo
import android.os.Environment; //导入依赖的package包/类
/**
* 获取SD卡信息
*
* @return SDCardInfo
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getSDCardInfo() {
if (!isSDCardEnable()) return null;
SDCardInfo sd = new SDCardInfo();
sd.isExist = true;
StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
sd.totalBlocks = sf.getBlockCountLong();
sd.blockByteSize = sf.getBlockSizeLong();
sd.availableBlocks = sf.getAvailableBlocksLong();
sd.availableBytes = sf.getAvailableBytes();
sd.freeBlocks = sf.getFreeBlocksLong();
sd.freeBytes = sf.getFreeBytes();
sd.totalBytes = sf.getTotalBytes();
return sd.toString();
}
示例6: downloadvideo
import android.os.Environment; //导入依赖的package包/类
public void downloadvideo(String pathvideo)
{
if(pathvideo.contains(".mp4"))
{
File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"Facebook Videos");
directory.mkdirs();
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(pathvideo));
int Number=pref.getFileName();
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
File root = new File(Environment.getExternalStorageDirectory() + File.separator+"Facebook Videos");
Uri path = Uri.withAppendedPath(Uri.fromFile(root), "Video-"+Number+".mp4");
request.setDestinationUri(path);
DownloadManager dm = (DownloadManager)getActivity().getSystemService(getActivity().DOWNLOAD_SERVICE);
if(downloadlist.contains(pathvideo))
{
Toast.makeText(getActivity().getApplicationContext(),"The Video is Already Downloading",Toast.LENGTH_LONG).show();
}
else
{
downloadlist.add(pathvideo);
dm.enqueue(request);
Toast.makeText(getActivity().getApplicationContext(),"Downloading Video-"+Number+".mp4",Toast.LENGTH_LONG).show();
Number++;
pref.setFileName(Number);
}
}
}
示例7: createCustomCompressedImageWithExceptions
import android.os.Environment; //导入依赖的package包/类
private void createCustomCompressedImageWithExceptions(String image, String directoryPath, int maxWidth, int maxHeight, int quality, final Callback successCb, final Callback failureCb) throws IOException {
File imageFile = new ImageCompress(mContext)
.setMaxWidth(maxWidth)
.setMaxHeight(maxHeight)
.setQuality(quality)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setDestinationDirectoryPath(Environment.getExternalStorageDirectory().getPath())
.compressToFile(new File(uriPath.getRealPathFromURI(Uri.parse(image))), directoryPath);
if (imageFile != null) {
WritableMap response = Arguments.createMap();
response.putString("path", imageFile.getAbsolutePath());
response.putString("uri", Uri.fromFile(imageFile).toString());
response.putString("name", imageFile.getName());
response.putDouble("size", imageFile.length());
// Invoke success
successCb.invoke(response);
} else {
failureCb.invoke("Error getting compressed image path");
}
}
示例8: onClick
import android.os.Environment; //导入依赖的package包/类
@Override
public void onClick(View widget) {
// TODO Auto-generated method stub
// ��ͼƬURLת��Ϊ����·�������Խ�ͼƬ���������ͼƬ�������дΪһ���������������
String imageName = MD5.md5(url);
String sdcardPath = Environment.getExternalStorageDirectory().toString(); // ��ȡSDCARD��·��
//��ȡͼƬ����
String[] ss = url.split("\\.");
String ext = ss[ss.length - 1];
// ����ͼƬ���ֵĵ�ַ
String savePath = sdcardPath + "/" + context.getPackageName() + "/" + imageName + "." + ext;
File file = new File(savePath);
if (file.exists()) {
// �������¼�������һ���µ�activity��������ʾͼƬ
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "image/*");
context.startActivity(intent);
}
}
示例9: writeUserHelpLog
import android.os.Environment; //导入依赖的package包/类
public static void writeUserHelpLog(String key, String logInfo) {
try {
String cachePath = Environment.getExternalStorageDirectory().getPath() + File.separator + DOWNLOAD_FOLDER_NAME;
File dir = new File(cachePath);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(cachePath, "logInfo.txt");
if (!file.exists()) {
file.createNewFile();
}
if (file.exists()) {
FileWriter writer = new FileWriter(file, true);
writer.write("\n\n" + key + "=" + logInfo + "\n\n");
writer.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: fromGallery
import android.os.Environment; //导入依赖的package包/类
/**
* 启动手机相册
*/
private void fromGallery() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), IMAGE_NAME)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
startActivityForResult(intent, GALLERY_KITKAT_REQUEST);
} else {
startActivityForResult(intent, GALLERY_REQUEST);
}
// Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
// startActivityForResult(intent, 103);103
}
示例11: onPrepareOptionsMenu
import android.os.Environment; //导入依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean accountsRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), PrivacyManager.cAccounts, null).restricted;
boolean appsRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), PrivacyManager.cSystem, null).restricted;
boolean contactsRestricted = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), PrivacyManager.cContacts, null).restricted;
menu.findItem(R.id.menu_accounts).setEnabled(accountsRestricted);
menu.findItem(R.id.menu_applications).setEnabled(appsRestricted);
menu.findItem(R.id.menu_contacts).setEnabled(contactsRestricted);
boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
menu.findItem(R.id.menu_export).setEnabled(mounted);
menu.findItem(R.id.menu_import).setEnabled(mounted);
menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this));
menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this));
return super.onPrepareOptionsMenu(menu);
}
示例12: PcmPlayer
import android.os.Environment; //导入依赖的package包/类
public PcmPlayer(Context context, Handler handler) {
this.mContext = context;
this.audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, wBufferSize, AudioTrack.MODE_STREAM);
this.handler = handler;
audioTrack.setPlaybackPositionUpdateListener(this, handler);
cacheDir = context.getExternalFilesDir(Environment.DIRECTORY_MUSIC);
}
示例13: requestAllPaths
import android.os.Environment; //导入依赖的package包/类
private JSONObject requestAllPaths() throws JSONException {
Context context = cordova.getActivity();
JSONObject ret = new JSONObject();
ret.put("applicationDirectory", "file:///android_asset/");
ret.put("applicationStorageDirectory", toDirUrl(context.getFilesDir().getParentFile()));
ret.put("dataDirectory", toDirUrl(context.getFilesDir()));
ret.put("cacheDirectory", toDirUrl(context.getCacheDir()));
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
try {
ret.put("externalApplicationStorageDirectory", toDirUrl(context.getExternalFilesDir(null).getParentFile()));
ret.put("externalDataDirectory", toDirUrl(context.getExternalFilesDir(null)));
ret.put("externalCacheDirectory", toDirUrl(context.getExternalCacheDir()));
ret.put("externalRootDirectory", toDirUrl(Environment.getExternalStorageDirectory()));
}
catch(NullPointerException e) {
/* If external storage is unavailable, context.getExternal* returns null */
LOG.d(LOG_TAG, "Unable to access these paths, most liklely due to USB storage");
}
}
return ret;
}
示例14: testFileExists
import android.os.Environment; //导入依赖的package包/类
/**
* Determine if a file or directory exists.
* @param name The name of the file to check.
* @return T=exists, F=not found
*/
public static boolean testFileExists(String name) {
boolean status;
// If SD card exists
if ((testSaveLocationExists()) && (!name.equals(""))) {
File path = Environment.getExternalStorageDirectory();
File newPath = constructFilePaths(path.toString(), name);
status = newPath.exists();
}
// If no SD card
else {
status = false;
}
return status;
}
示例15: testSaveLocationExists
import android.os.Environment; //导入依赖的package包/类
/**
* Determine if SD card exists.
*
* @return T=exists, F=not found
*/
public static boolean testSaveLocationExists() {
String sDCardStatus = Environment.getExternalStorageState();
boolean status;
// If SD card is mounted
if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
status = true;
}
// If no SD card
else {
status = false;
}
return status;
}