Java Code Examples for android.os.Environment.isExternalStorageRemovable()

The following are Jave code examples for showing how to use isExternalStorageRemovable() of the android.os.Environment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: magic_imageloader_network   File: DiskUtils.java   View Source Code Vote up 6 votes
public static String getDiskCacheDir(Context context) {
    File cacheFile = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cacheFile = context.getExternalCacheDir();
    } else {
        cacheFile = context.getCacheDir();
    }
    if (cacheFile != null) {
        return cacheFile.getPath();
    } else {
        String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
        return Environment.getExternalStorageDirectory().getPath() + cacheDir;
    }
}
 
Example 2
Project: decoy   File: UtilImags.java   View Source Code Vote up 6 votes
public static final String SHOWFILEURL(Context context) throws IOException
{
    String cachePath;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath =context.getCacheDir().getPath();
    }
    File file = new File(cachePath+"/thumb");
    if (!file.exists()) {
        try {
            file.mkdirs();
        } catch (Exception e) {
        }
    }
    return cachePath+File.separator+"thumb";
}
 
Example 3
Project: starcor.xul   File: XulSystemUtil.java   View Source Code Vote up 6 votes
public static String getDiskCacheDir(Context context) {
    String cacheDir;

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
        && !Environment.isExternalStorageRemovable()) {
        cacheDir = getExternalCacheDir(context);
        // 部分机型返回了null
        if (cacheDir == null) {
            cacheDir = getInternalCacheDir(context);
        }
    } else {
        cacheDir = getInternalCacheDir(context);
    }
    if(!checkCacheAvailable(cacheDir)){
        return getBackUpPath(context);
    }
    return cacheDir;
}
 
Example 4
Project: SuperHttp   File: DiskCache.java   View Source Code Vote up 5 votes
private static File getDiskCacheDir(Context context, String dirName) {
    String cachePath;
    if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable())
            && context.getExternalCacheDir() != null) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return new File(cachePath + File.separator + dirName);
}
 
Example 5
Project: Utils   File: FileUtil.java   View Source Code Vote up 5 votes
/**
 * 获取缓存目录
 *
 * @param context
 * @return
 */
public static String getDiskCacheDir(Context context) {
    String cachePath = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return cachePath;
}
 
Example 6
Project: CommonFramework   File: CrashCaptureHandler.java   View Source Code Vote up 5 votes
/**
 * 通过context获取APP缓存文件夹路径,用于缓存数据
 *
 * @param context
 * @return
 */
private String getDiskCacheDir(Context context) {
    String cachePath;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return cachePath;
}
 
Example 7
Project: SuperHttp   File: DownloadRequest.java   View Source Code Vote up 5 votes
private String getDiskCachePath(Context context) {
    String cachePath;
    if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable())
            && context.getExternalCacheDir() != null) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return cachePath;
}
 
Example 8
Project: Watermark   File: Utils.java   View Source Code Vote up 5 votes
public static boolean isExternalStorageAvailable() {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
        return true;
    } else {
        return false;
    }
}
 
Example 9
Project: Android-Practice   File: ImageCache.java   View Source Code Vote up 5 votes
/**
 * Check if external storage is built-in or removable.
 *
 * @return True if external storage is removable (like an SD card), false
 *         otherwise.
 */
@TargetApi(VERSION_CODES.GINGERBREAD)
public static boolean isExternalStorageRemovable() {
    if (Utils.hasGingerbread()) {
        return Environment.isExternalStorageRemovable();
    }
    return true;
}
 
Example 10
Project: RxEasyHttp   File: RxCache.java   View Source Code Vote up 5 votes
/**
 * 应用程序缓存原理:
 * 1.当SD卡存在或者SD卡不可被移除的时候,就调用getExternalCacheDir()方法来获取缓存路径,否则就调用getCacheDir()方法来获取缓存路径<br>
 * 2.前者是/sdcard/Android/data/<application package>/cache 这个路径<br>
 * 3.后者获取到的是 /data/data/<application package>/cache 这个路径<br>
 *
 * @param uniqueName 缓存目录
 */
public File getDiskCacheDir(Context context, String uniqueName) {
    File cacheDir;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cacheDir = context.getExternalCacheDir();
    } else {
        cacheDir = context.getCacheDir();
    }
    if (cacheDir == null) {// if cacheDir is null throws NullPointerException
        cacheDir = context.getCacheDir();
    }
    return new File(cacheDir.getPath() + File.separator + uniqueName);
}
 
Example 11
Project: ViseFace   File: FaceDetectorActivity.java   View Source Code Vote up 5 votes
private String getDiskCacheDir(Context context, String dirName) {
    String cachePath = "";
    if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable())
            && context != null && context.getExternalCacheDir() != null) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        if (context != null && context.getCacheDir() != null) {
            cachePath = context.getCacheDir().getPath();
        }
    }
    return cachePath + File.separator + dirName;
}
 
Example 12
Project: DisplayingBitmaps   File: ImageCache.java   View Source Code Vote up 5 votes
/**
 * Check if external storage is built-in or removable.
 *
 * @return True if external storage is removable (like an SD card), false
 *         otherwise.
 */
@TargetApi(VERSION_CODES.GINGERBREAD)
public static boolean isExternalStorageRemovable() {
    if (Utils.hasGingerbread()) {
        return Environment.isExternalStorageRemovable();
    }
    return true;
}
 
Example 13
Project: SuperSelector   File: ImageCache.java   View Source Code Vote up 5 votes
/**
 * Check if external storage is built-in or removable.
 * 
 * @return True if external storage is removable (like an SD card), false
 *         otherwise.
 */
@TargetApi(VERSION_CODES.GINGERBREAD)
public static boolean isExternalStorageRemovable() {
	if (Utils.hasGingerbread()) {
		return Environment.isExternalStorageRemovable();
	}
	return true;
}
 
Example 14
Project: javaide   File: SysUtils.java   View Source Code Vote up 5 votes
public static File getFileDir(Context context) {
    File fileDir;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        fileDir = context.getExternalFilesDir(null);
        if(fileDir == null)
            fileDir = context.getFilesDir();
    } else {
        fileDir = context.getFilesDir();
    }
    return fileDir;
}
 
Example 15
Project: MovingGdufe-Android   File: FileUtils.java   View Source Code Vote up 5 votes
/**
 * 获取硬盘的缓存目录,用来放图片
 * http://blog.csdn.net/u011494050/article/details/39671159
 * @param context context
 * @return 路径
 */
private static String getDiskCacheDir(Context context) {
    String cachePath = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        try{
            cachePath = context.getExternalCacheDir().getPath();//SDCard/Android/data/应用包名/cache/目录
        }catch (NullPointerException e){
            cachePath = context.getCacheDir().getPath();    //data/data/<application package>/cache
        }
    } else {
        cachePath = context.getCacheDir().getPath();    //data/data/<application package>/cache
    }
    return cachePath;
}
 
Example 16
Project: Utils   File: FileUtil.java   View Source Code Vote up 5 votes
/**
 * 获取缓存视频文件目录
 *
 * @param context
 * @return
 */
public static String getDiskFileDir(Context context) {
    String cachePath = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getPath();
    } else {
        cachePath = context.getFilesDir().getPath();
    }
    return cachePath;
}
 
Example 17
Project: OSchina_resources_android   File: DiskLruCacheUtil.java   View Source Code Vote up 5 votes
/**
 * 获取相应的缓存目录
 *
 * @param context
 * @param uniqueName
 * @return
 */
public static File getDiskCacheDir(Context context, String uniqueName) {
    String cachePath;
    if (Environment.MEDIA_MOUNTED.equals(Environment
            .getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return new File(cachePath + File.separator + uniqueName);
}
 
Example 18
Project: MegviiFacepp-Android-SDK   File: ConUtil.java   View Source Code Vote up 5 votes
public static String getSDRootPath(){
	if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
		return Environment.getExternalStorageDirectory().getPath();
	} else {
		return null;
	}

}
 
Example 19
Project: SmartMath   File: AndroidStorageOptions.java   View Source Code Vote up 4 votes
@SuppressLint("NewApi")
@SuppressWarnings("unchecked")
   private static void setProperties() {
       /*
        * At this point all the paths in the list should be valid. Build the
        * public properties.
        */
       mLabels = new ArrayList<String>();

       int j = 0;
       if (mMounts.size() > 0) {
           if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD)
               mLabels.add(AppSmartMath.getContext().getString(R.string.auto));
           else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
               if (Environment.isExternalStorageRemovable()) {
                   mLabels.add(AppSmartMath.getContext().getString(R.string.external_sd_card) + " 1");
                   j = 1;
               } else
                   mLabels.add(AppSmartMath.getContext().getString(R.string.internal_storage));
           } else {
               if (!Environment.isExternalStorageRemovable()
                       || Environment.isExternalStorageEmulated())
                   mLabels.add(AppSmartMath.getContext().getString(R.string.internal_storage));
               else {
                   mLabels.add(AppSmartMath.getContext().getString(R.string.external_sd_card) + " 1");
                   j = 1;
               }
           }

           if (mMounts.size() > 1) {
               for (int i = 1; i < mMounts.size(); i++) {
                   mLabels.add(AppSmartMath.getContext().getString(R.string.external_sd_card)  + (i + j));
               }
           }
       }

       labels = new String[mLabels.size()];
       mLabels.toArray(labels);

       paths = new String[mMounts.size()];
       mMounts.toArray(paths);
       count = Math.min(labels.length, paths.length);

   }
 
Example 20
Project: utilsLibrary   File: FileUtils.java   View Source Code Vote up 4 votes
/**
 * 查询设备是否有不可被移除的sd卡
 *
 * @return true 有,false 没有
 */
public static boolean hasSDCard() {

    return Environment.getExternalStorageState()
            .equals(Environment.MEDIA_MOUNTED) && !Environment.isExternalStorageRemovable();
}