当前位置: 首页>>代码示例>>Java>>正文


Java Environment类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:26,代码来源:ChatFragment.java

示例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);
    }
}
 
开发者ID:redleaf2002,项目名称:downloadmanager,代码行数:24,代码来源:Helpers.java

示例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;
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:22,代码来源:FileUtils.java

示例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();
    }
}
 
开发者ID:humaniq,项目名称:humaniq-android,代码行数:19,代码来源:Wallet.java

示例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();
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:21,代码来源:SDCardUtils.java

示例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);
        }

    }
}
 
开发者ID:adarshgumashta,项目名称:Facebook-Video-Downloader,代码行数:31,代码来源:HomeFragment.java

示例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");
    }
}
 
开发者ID:emekalites,项目名称:react-native-compress-image,代码行数:23,代码来源:ImageCompressModule.java

示例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);
	}
}
 
开发者ID:didikee,项目名称:cnBetaGeek,代码行数:24,代码来源:MyTagHandler.java

示例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();
    }
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:23,代码来源:TmpFolderUtils.java

示例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
    }
 
开发者ID:linsir6,项目名称:TripBuyer,代码行数:20,代码来源:UploadAirTicketActivity.java

示例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);
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:21,代码来源:ActivityApp.java

示例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);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:8,代码来源:PcmPlayer.java

示例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;
}
 
开发者ID:alex-shpak,项目名称:keemob,代码行数:22,代码来源:FileUtils.java

示例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;
}
 
开发者ID:rodrigonsh,项目名称:alerta-fraude,代码行数:21,代码来源:DirectoryManager.java

示例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;
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:21,代码来源:DirectoryManager.java


注:本文中的android.os.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。