Java Code Examples for android.os.Environment#MEDIA_MOUNTED

The following examples show how to use android.os.Environment#MEDIA_MOUNTED . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private static boolean isStorageWritable() {
    boolean isExternalStorageAvailable;
    boolean isExternalStorageWritable;
    String state = Environment.getExternalStorageState();
    switch (state) {
        case Environment.MEDIA_MOUNTED:
            isExternalStorageAvailable = true;
            isExternalStorageWritable = true;
            break;
        case Environment.MEDIA_MOUNTED_READ_ONLY:
            isExternalStorageAvailable = true;
            isExternalStorageWritable = false;
            break;
        default:
            isExternalStorageAvailable = false;
            isExternalStorageWritable = false;
            break;
    }
    return isExternalStorageAvailable && isExternalStorageWritable;
}
 
Example 2
Source Project: v2ex-daily-android   File: Application.java    License: Apache License 2.0 6 votes vote down vote up
private void initiImageLoader() {
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.EXACTLY)
            .cacheOnDisc(true)
            .displayer(new FadeInBitmapDisplayer(200))
            .showImageOnLoading(R.drawable.ic_launcher)
            .build();

    File cacheDir;
    if(Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED){
        cacheDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    }else{
        cacheDir = getCacheDir();
    }
    ImageLoaderConfiguration.Builder configBuilder = new ImageLoaderConfiguration.Builder(mContext)
            .threadPoolSize(2)
            .memoryCache(new WeakMemoryCache())
            .denyCacheImageMultipleSizesInMemory()
            .discCache(new UnlimitedDiscCache(cacheDir))
            .defaultDisplayImageOptions(options);
    if(BuildConfig.DEBUG){
        configBuilder.writeDebugLogs();
    }
    ImageLoader.getInstance().init(configBuilder.build());
}
 
Example 3
Source Project: Android-ImageManager   File: Utils.java    License: MIT License 6 votes vote down vote up
public static File getDiskCacheDir(final Context context, final String uniqueName) {
    // Check if media is mounted or storage is built-in, if so, try and use external cache dir
    // otherwise use internal cache dir
    final boolean externalCacheAvailable = (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) ||
                                           !Utils.isExternalStorageRemovable();

    String cachePath = null;

    if (externalCacheAvailable && Utils.getExternalCacheDir(context) != null) {
        cachePath = Utils.getExternalCacheDir(context).getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }

    return new File(cachePath + File.separator + uniqueName);
}
 
Example 4
private static File prepareTargetDirectory() throws DownloadFailException, IOException {
    File downloadFolder =
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    if (
            downloadFolder
                    != null
                    && (downloadFolder.exists() || downloadFolder.mkdir() || downloadFolder.createNewFile())
                    && downloadFolder.canWrite()
    ) {
        return downloadFolder;
    }

    File externalStorage = Environment.getExternalStorageDirectory();
    String externalStorageState = Environment.getExternalStorageState();
    if (
            externalStorage
                    != null
                    && (externalStorage.exists() || externalStorage.mkdir() || externalStorage.createNewFile())
                    && externalStorage.canWrite()
                    && externalStorageState.equals(Environment.MEDIA_MOUNTED)
    ) {
        return new File(externalStorage, "Download");
    }

    File appExternal = LMvdApp.getInstance().getExternalFilesDir(null);
    if (
            appExternal
                    != null
                    && (appExternal.exists() || appExternal.mkdir() || appExternal.createNewFile())
                    && appExternal.canWrite()
    ) {
        return new File(appExternal, "Download");
    }

    String message;
    switch (externalStorageState) {
        case Environment.MEDIA_UNMOUNTABLE:
            message = "External storage is un-mountable.";
            break;
        case Environment.MEDIA_SHARED:
            message = "USB mass storage is turned on. Can not mount external storage.";
            break;
        case Environment.MEDIA_UNMOUNTED:
            message = "External storage is not mounted.";
            break;
        case Environment.MEDIA_MOUNTED_READ_ONLY:
            message = "External storage is mounted but has no write access.";
            break;
        case Environment.MEDIA_BAD_REMOVAL:
            message = "External storage was removed without being properly ejected.";
            break;
        case Environment.MEDIA_REMOVED:
            message = "External storage does not exist. Probably removed.";
            break;
        case Environment.MEDIA_NOFS:
            message = "External storage is blank or has unsupported filesystem.";
            break;
        case Environment.MEDIA_CHECKING:
            message = "Still checking for external storage.";
            break;
        case Environment.MEDIA_EJECTING:
            message = "External storage is currently being ejected.";
            break;
        case Environment.MEDIA_UNKNOWN:
            message = "External storage is not available for some unknown reason.";
            break;
        case Environment.MEDIA_MOUNTED:
            message = "External storage is mounted but for some unknown reason is not" +
                    " available.";
            break;
        default:
            message = "External storage is not available. No reason.";
    }
    throw new DownloadFailException(message);
}
 
Example 5
Source Project: FontTextView   File: MainActivity.java    License: MIT License 4 votes vote down vote up
@Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.set_path_button:
                mFontTextView.setFontPath("fonts/my_font.ttf");
                break;
            case R.id.create_button:
                v.setEnabled(false);    // can click only once
                ViewGroup parent = (ViewGroup) findViewById(R.id.container_layout);
                createFontTextView(parent, "fonts/my_font.ttf");
//                createTextView(parent, "fonts/my_font.ttf");
                break;
            case R.id.replace_font_from_asset_btn:
                /* Method 3: replace system default font */
                FontUtils.getInstance().replaceSystemDefaultFontFromAsset(this, "fonts/my_font.ttf");
                recreate();
                break;
            case R.id.replace_font_from_file_btn:
                if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
                    String fontPath = Environment.getExternalStorageDirectory() + "/whinc/my_font.ttf";
                    FontUtils.getInstance().replaceSystemDefaultFontFromFile(this, fontPath);
                    recreate();
                } else {
                    Toast.makeText(this, "External storage is not accessible!", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.add_view_btn:
                v.setEnabled(false);    // can click only once
                Button button = new Button(this, null, R.attr.buttonStyle);
                button.setText("Button");
                RelativeLayout layout = (RelativeLayout) findViewById(R.id.font_text_layout);
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                lp.addRule(RelativeLayout.CENTER_IN_PARENT);
                layout.addView(button, lp);
                break;
            default:
                break;
        }
    }
 
Example 6
Source Project: ArcgisTool   File: FileTools.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 判断sdcard是否已经挂载
 * @param context
 * @return
 */
public static boolean hasSdcard(Context context){
    return  Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED;
}
 
Example 7
Source Project: AndroidDownload   File: FileTools.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 判断sdcard是否已经挂载
 * @param context
 * @return
 */
public static boolean hasSdcard(Context context){
    return  Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED;
}