Java Code Examples for android.os.Environment#MEDIA_MOUNTED

The following examples show how to use android.os.Environment#MEDIA_MOUNTED . 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 check out the related API usage on the sidebar.
Example 1
Source File: FileHelper.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
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 File: Application.java    From v2ex-daily-android with 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 File: Utils.java    From Android-ImageManager with 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
Source File: DownloadManager.java    From Beedio with GNU General Public License v2.0 4 votes vote down vote up
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 File: MainActivity.java    From FontTextView with 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 File: FileTools.java    From ArcgisTool with 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 File: FileTools.java    From AndroidDownload with 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;
}