List of usage examples for android.content Context STORAGE_SERVICE
String STORAGE_SERVICE
To view the source code for android.content Context STORAGE_SERVICE.
Click Source Link
From source file:Main.java
private static String[] getExternalDirs(Context context) { Context mContext = context.getApplicationContext(); StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); try {// ww w . j a v a2s . co m Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume"); Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList"); Method getPath = storageVolumeClazz.getMethod("getPath"); Object result = getVolumeList.invoke(mStorageManager); final int length = Array.getLength(result); final String[] paths = new String[length]; for (int i = 0; i < length; i++) { Object storageVolumeElement = Array.get(result, i); paths[i] = (String) getPath.invoke(storageVolumeElement); } return paths; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static List<String> getDirs(Context context) { List<String> dirs = new ArrayList<String>(); StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); try {/*w w w . ja v a2s .co m*/ Class[] paramClasses = {}; Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", paramClasses); getVolumePathsMethod.setAccessible(true); Object[] params = {}; Object invoke = getVolumePathsMethod.invoke(storageManager, params); for (int i = 0; i < ((String[]) invoke).length; i++) { // System.out.println(((String[])invoke)[i]); dirs.add(((String[]) invoke)[i]); } } catch (Exception e) { e.printStackTrace(); } return dirs; }
From source file:Main.java
public static String getAvailableStoragePath(Context context) { if (BASE_DIR == null) { try {// w w w. j av a2 s .c o m BASE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath(); StorageManager sStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); Class<?> smClazz = sStorageManager.getClass(); Method listMethod = smClazz.getDeclaredMethod("getVolumeList"); Object vlObject = listMethod.invoke(sStorageManager); if (vlObject.getClass().isArray()) { String state = null; String path = null; // Class svClazz = // Class.forName("android.os.storage.StorageVolume"); Object svObject = Array.get(vlObject, 1); if (svObject != null) { Method pathMethod = svObject.getClass().getMethod("getPath"); path = (String) pathMethod.invoke(svObject); Method stateMethod = smClazz.getMethod("getVolumeState", new Class[] { String.class }); state = (String) stateMethod.invoke(sStorageManager, path); } if (path != null && state != null && state.equals(Environment.MEDIA_MOUNTED)) { BASE_DIR = path; } else { BASE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath(); } } } catch (Exception e) { BASE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath(); } return BASE_DIR; } else { return BASE_DIR; } }
From source file:Main.java
private static void ensureStorageManager(Context context) { if (sStorageManager == null) { sStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); }//from ww w . j av a 2s. c o m }
From source file:com.frostwire.android.gui.StoragePicker.java
private static String getFullPathFromTreeUri(Context ctx, final Uri treeUri) { if (treeUri == null) { return null; }//from ww w . j a v a 2s. co m StorageManager mStorageManager = (StorageManager) ctx.getSystemService(Context.STORAGE_SERVICE); String volumePath = getVolumePath(mStorageManager, getVolumeIdFromTreeUri(treeUri)); if (volumePath == null) { return File.separator; } if (volumePath.endsWith(File.separator)) { volumePath = volumePath.substring(0, volumePath.length() - 1); } String documentPath = getDocumentPathFromTreeUri(treeUri); if (documentPath.endsWith(File.separator)) { documentPath = documentPath.substring(0, documentPath.length() - 1); } if (documentPath.length() > 0) { if (documentPath.startsWith(File.separator)) { return volumePath + documentPath; } else { return volumePath + File.separator + documentPath; } } else { return volumePath; } }
From source file:com.nick.scalpel.core.AutoFoundWirer.java
private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme, Field field, Object forWho) { Resources resources = context.getResources(); switch (type) { case STRING://from w ww.ja v a 2 s.c o m setField(field, forWho, resources.getString(idRes)); break; case COLOR: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, resources.getColor(idRes, theme)); } else { //noinspection deprecation setField(field, forWho, resources.getColor(idRes)); } break; case INTEGER: setField(field, forWho, resources.getInteger(idRes)); break; case BOOL: setField(field, forWho, resources.getBoolean(idRes)); break; case STRING_ARRAY: setField(field, forWho, resources.getStringArray(idRes)); break; case INT_ARRAY: setField(field, forWho, resources.getIntArray(idRes)); break; case PM: setField(field, forWho, context.getSystemService(Context.POWER_SERVICE)); break; case ACCOUNT: setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE)); break; case ALARM: setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE)); break; case AM: setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE)); break; case WM: setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE)); break; case NM: setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE)); break; case TM: setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE)); break; case TCM: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE)); } break; case SP: setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context)); break; case PKM: setField(field, forWho, context.getPackageManager()); break; case HANDLE: setField(field, forWho, new Handler(Looper.getMainLooper())); break; case ASM: setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE)); break; case CAP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE)); } break; case KGD: setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE)); break; case LOCATION: setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE)); break; case SEARCH: setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE)); break; case SENSOR: setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE)); break; case STORAGE: setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE)); break; case WALLPAPER: setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE)); break; case VIBRATOR: setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE)); break; case CONNECT: setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE)); break; case NETWORK_STATUS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE)); } break; case WIFI: setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE)); break; case AUDIO: setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE)); break; case FP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE)); } break; case MEDIA_ROUTER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE)); } break; case SUB: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)); } break; case IME: setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE)); break; case CLIP_BOARD: setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE)); break; case APP_WIDGET: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE)); } break; case DEVICE_POLICY: setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE)); break; case DOWNLOAD: setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE)); break; case BATTERY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE)); } break; case NFC: setField(field, forWho, context.getSystemService(Context.NFC_SERVICE)); break; case DISPLAY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE)); } break; case USER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.USER_SERVICE)); } break; case APP_OPS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE)); } break; case BITMAP: setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null)); break; } }
From source file:com.lee.sdk.utils.Utils.java
/** * ?volume/*from w w w.j a v a 2s . c o m*/ * * @param context context * @return Volume */ public static Object[] getVolumeList(Context context) { StorageManager manager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); Object[] result = null; Object o = invokeHideMethodForObject(manager, "getVolumeList", null, null); if (o != null) { result = (Object[]) o; } return result; }
From source file:com.lee.sdk.utils.Utils.java
/** * ??volume?/* ww w . j a v a2s . c o m*/ * * @param context context * @param volumePath volumePath * @return result */ public static String getVolumeState(Context context, String volumePath) { StorageManager manager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); String result = ""; Object o = invokeHideMethodForObject(manager, "getVolumeState", new Class[] { String.class }, new Object[] { volumePath }); if (o != null) { result = (String) o; } return result; }
From source file:com.frostwire.android.LollipopFileSystem.java
private static String getPath(Context context, Uri treeUri, boolean tree) { if (treeUri == null) { return null; }//from w ww .j av a 2 s .c om StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); String volumePath = getVolumePath(mStorageManager, getVolumeIdFromTreeUri(treeUri)); if (volumePath == null) { return File.separator; } if (volumePath.endsWith(File.separator)) { volumePath = volumePath.substring(0, volumePath.length() - 1); } String documentPath = getDocumentPathFromTreeUri(treeUri, tree); if (documentPath.endsWith(File.separator)) { documentPath = documentPath.substring(0, documentPath.length() - 1); } String path = volumePath; if (documentPath.length() > 0) { if (documentPath.startsWith(File.separator)) { path = volumePath + documentPath; } else { path = volumePath + File.separator + documentPath; } } return path; }
From source file:com.frostwire.android.LollipopFileSystem.java
private static String getVolumeId(Context context, final String volumePath) { try {/*from w w w .j a v a2 s . com*/ StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume"); Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList"); Method getUuid = storageVolumeClazz.getMethod("getUuid"); Method getPath = storageVolumeClazz.getMethod("getPath"); Object result = getVolumeList.invoke(mStorageManager); final int length = Array.getLength(result); for (int i = 0; i < length; i++) { Object storageVolumeElement = Array.get(result, i); String path = (String) getPath.invoke(storageVolumeElement); if (path != null) { if (path.equals(volumePath)) { return (String) getUuid.invoke(storageVolumeElement); } } } // not found. return null; } catch (Exception ex) { return null; } }