當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。