当前位置: 首页>>代码示例>>Java>>正文


Java StorageManager类代码示例

本文整理汇总了Java中android.os.storage.StorageManager的典型用法代码示例。如果您正苦于以下问题:Java StorageManager类的具体用法?Java StorageManager怎么用?Java StorageManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StorageManager类属于android.os.storage包,在下文中一共展示了StorageManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestPermission

import android.os.storage.StorageManager; //导入依赖的package包/类
private void requestPermission() {
    try {
        StorageManager sm = getSystemService(StorageManager.class);
        StorageVolume volume = sm.getPrimaryStorageVolume();
        Intent intent = volume.createAccessIntent(Environment.DIRECTORY_DOWNLOADS);
        startActivityForResult(intent, REQUEST_CODE);
    } catch (Exception e) {
        //Toast.makeText(this, R.string.cannot_request_permission, Toast.LENGTH_LONG).show();
        Toast.makeText(this, "Can't use Scoped Directory Access.\nFallback to runtime permission.", Toast.LENGTH_LONG).show();
        Log.wtf("FFM", "can't use Scoped Directory Access", e);

        Crashlytics.logException(e);

        // fallback to runtime permission
        if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
        }
    }
}
 
开发者ID:RikkaApps,项目名称:FCM-for-Mojo,代码行数:20,代码来源:MainActivity.java

示例2: getVolumePaths

import android.os.storage.StorageManager; //导入依赖的package包/类
private static String[] getVolumePaths(Context context) {
    String[] volumes = null;
    StorageManager managerStorage = (StorageManager) context.getSystemService("storage");
    if (managerStorage == null) {
        return volumes;
    }
    try {
        return (String[]) managerStorage.getClass().getMethod("getVolumePaths", new Class[0]).invoke(managerStorage, new Object[0]);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        return volumes;
    } catch (IllegalArgumentException e2) {
        e2.printStackTrace();
        return volumes;
    } catch (IllegalAccessException e3) {
        e3.printStackTrace();
        return volumes;
    } catch (InvocationTargetException e4) {
        e4.printStackTrace();
        return volumes;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:SystemUtils.java

示例3: isSdcardMounted

import android.os.storage.StorageManager; //导入依赖的package包/类
private static int isSdcardMounted(String path, Context context) {
    StorageManager managerStorage = (StorageManager) context.getSystemService("storage");
    if (managerStorage == null) {
        return -1;
    }
    try {
        Method method = managerStorage.getClass().getDeclaredMethod("getVolumeState", new Class[]{String.class});
        method.setAccessible(true);
        if ("mounted".equalsIgnoreCase((String) method.invoke(managerStorage, new Object[]{path}))) {
            return 1;
        }
        return 0;
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        return -1;
    } catch (IllegalArgumentException e2) {
        e2.printStackTrace();
        return -1;
    } catch (IllegalAccessException e3) {
        e3.printStackTrace();
        return -1;
    } catch (InvocationTargetException e4) {
        e4.printStackTrace();
        return -1;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:SystemUtils.java

示例4: AppPagerAdapter

import android.os.storage.StorageManager; //导入依赖的package包/类
public AppPagerAdapter(FragmentManager fm) {
    super(fm);
    titles.add("Clone Apps");
    dirs.add(null);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Context ctx = VApp.getApp();
        StorageManager storage = (StorageManager) ctx.getSystemService(Context.STORAGE_SERVICE);
        for (StorageVolume volume : storage.getStorageVolumes()) {
            //Why the fuck are getPathFile and getUserLabel hidden?!
            //StorageVolume is kinda useless without those...
            File dir = Reflect.on(volume).call("getPathFile").get();
            String label = Reflect.on(volume).call("getUserLabel").get();
            if (dir.listFiles() != null) {
                titles.add(label);
                dirs.add(dir);
            }
        }
    } else {
        // Fallback: only support the default storage sources
        File storageFir = Environment.getExternalStorageDirectory();
        if (storageFir.list() != null) {
            titles.add("Ghost Installation");
            dirs.add(storageFir);
        }
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:27,代码来源:AppPagerAdapter.java

示例5: getMountedPoints

import android.os.storage.StorageManager; //导入依赖的package包/类
public static ArrayList<String> getMountedPoints(Context context) {
    StorageManager manager = (StorageManager)
            context.getSystemService(Activity.STORAGE_SERVICE);
    ArrayList<String> mountedPoints = new ArrayList<String>();
    try {
        Method getVolumePaths = manager.getClass().getMethod("getVolumePaths");
        String[] points = (String[]) getVolumePaths.invoke(manager);
        if (points != null && points.length > 0) {
            Method getVolumeState = manager.getClass().getMethod("getVolumeState", String.class);
            for (String point : points) {
                String state = (String) getVolumeState.invoke(manager, point);
                if (Environment.MEDIA_MOUNTED.equals(state))
                    mountedPoints.add(point);
            }
            return mountedPoints;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:22,代码来源:StorageManagerCompat.java

示例6: getStorageDirectories

import android.os.storage.StorageManager; //导入依赖的package包/类
/**
 * Get all available storage directories.
 * Inspired by CyanogenMod File Manager:
 * https://github.com/CyanogenMod/android_packages_apps_CMFileManager
 */
public static Set<File> getStorageDirectories(Context context) {
    if (storageDirectories == null) {
        try {
            // Use reflection to retrieve storage volumes because required classes and methods are hidden in AOSP.
            StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
            Method method = storageManager.getClass().getMethod("getVolumeList");
            StorageVolume[] storageVolumes = (StorageVolume[]) method.invoke(storageManager);
            if (storageVolumes != null && storageVolumes.length > 0) {
                storageDirectories = new HashSet<>();
                for (StorageVolume volume : storageVolumes) {
                    storageDirectories.add(new File(volume.getPath()));
                }
            }

        } catch (Exception e) {
            Log.e(LOG_TAG, e.getMessage());
        }
    }
    return storageDirectories;
}
 
开发者ID:meonwax,项目名称:soundboard,代码行数:26,代码来源:FileUtils.java

示例7: checkStorageMountState

import android.os.storage.StorageManager; //导入依赖的package包/类
private static boolean checkStorageMountState(Context context, String mountPoint) {
    if (mountPoint == null) {
        return false;
    }
    StorageManager storageManager = (StorageManager) context
            .getSystemService(Context.STORAGE_SERVICE);
    try {
        Method getVolumeState = storageManager.getClass().getMethod(
                "getVolumeState", String.class);
        String state = (String) getVolumeState.invoke(storageManager,
                mountPoint);
        return Environment.MEDIA_MOUNTED.equals(state);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:jiajunhui,项目名称:FileBase,代码行数:18,代码来源:StorageEngine.java

示例8: StorageUtils

import android.os.storage.StorageManager; //导入依赖的package包/类
public StorageUtils(Context context) 
{
	mContext = context;
	if (mContext != null) 
	{
		mStorageManager = (StorageManager)mContext.getSystemService(Activity.STORAGE_SERVICE);
		try 
		{
			mMethodGetPaths = mStorageManager.getClass().getMethod("getVolumePaths");
		} 
		catch (NoSuchMethodException e) 
		{
			e.printStackTrace();
		}
	}
}
 
开发者ID:weizhiping,项目名称:ebook,代码行数:17,代码来源:StorageUtils.java

示例9: isVulnerable

import android.os.storage.StorageManager; //导入依赖的package包/类
@Override
public boolean isVulnerable(Context context) throws Exception {
    int pid = SystemUtils.ProcfindPidFor("/system/bin/vold");
    StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);

    Method getObbPath = sm.getClass().getMethod("getMountedObbPath", String.class);
    getObbPath.invoke(sm, "AAAA AAAA AAAA AAAA "
            + "AAAA AAAA AAAA AAAA "
            + "AAAA AAAA AAAA AAAA "
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA"
            + "AAAA AAAA AAAA AAAA");

    Thread.sleep(2000);  // give vold some time to crash

    return false;
}
 
开发者ID:AndroidVTS,项目名称:android-vts,代码行数:23,代码来源:ZergRush.java

示例10: getVolumeListApi24

import android.os.storage.StorageManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
private static List<MountVolume> getVolumeListApi24(Context context) {
    StorageManager storageManager = context.getSystemService(StorageManager.class);
    List<StorageVolume> volumes = storageManager.getStorageVolumes();
    List<MountVolume> list = new ArrayList<MountVolume>(volumes.size());
    List<String> fileList = getMountsList();
    for (StorageVolume volume : volumes) {
        MountVolume mountVolume = new MountVolume();
        mountVolume.setUuid(volume.isPrimary() ? "primary" : volume.getUuid());
        mountVolume.setPathFile(volume.isPrimary() ? new File(getFilePath(fileList, "emulated") + "/0") : new File(getFilePath(fileList, volume.getUuid())));
        mountVolume.setPrimary(volume.isPrimary());
        mountVolume.setEmulated(volume.isEmulated());
        mountVolume.setRemovable(volume.isRemovable());
        mountVolume.setDescription(volume.getDescription(context));
        mountVolume.setState(volume.getState());
        list.add(mountVolume);
    }
    return list;
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:20,代码来源:Utilities.java

示例11: getPathStorage

import android.os.storage.StorageManager; //导入依赖的package包/类
/**
 * 获取路径根目录
 *
 * @param manager 存储设备管理器
 * @param path    路径
 * @return 根目录
 */
public static String getPathStorage(StorageManager manager, String path) {
    if (StringUtils.isNullOrEmpty(path))
        return null;
    List<AMStorageManagerCompat.StorageVolumeImpl> volumes =
            AMStorageManagerCompat.getEmulatedStorageVolumes(manager);
    if (volumes.size() < 1)
        return null;
    String storage = null;
    for (AMStorageManagerCompat.StorageVolumeImpl volume : volumes) {
        final String storagePath = volume.getPath();
        if (path.startsWith(storagePath)) {
            storage = storagePath;
            break;
        }
    }
    return storage;
}
 
开发者ID:AlexMofer,项目名称:ProjectX,代码行数:25,代码来源:FileUtils.java

示例12: getStoragePathsCompat

import android.os.storage.StorageManager; //导入依赖的package包/类
String[] getStoragePathsCompat() {
    try {
        StorageManager sm = (StorageManager) appContext.getSystemService(Context.STORAGE_SERVICE);
        Method getVolumeList = StorageManager.class.getDeclaredMethod("getVolumeList");
        Class<?> volume = Class.forName("android.os.storage.StorageVolume");
        Method getPath =  volume.getDeclaredMethod("getPath");
        Object[] volumes = (Object[]) getVolumeList.invoke(sm);
        String[] paths = new String[volumes.length];
        for (int ii=0; ii<volumes.length; ii++) {
            paths[ii] = (String) getPath.invoke(volumes[ii]);
        }
        return paths;
    } catch (Exception e) {
        if (DUMPSTACKS) Timber.e(e, "getStoragePathsCompat");
    }
    Timber.w("Failed to get storage paths via reflection");
    return new String[0];
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:19,代码来源:StorageLookup.java

示例13: performTask

import android.os.storage.StorageManager; //导入依赖的package包/类
@Override
public List<Compilation> performTask() throws Throwable {
    List<String> pathList = new ArrayList<>();
    StorageManager sm = (StorageManager) WikipediaApp.getInstance().getSystemService(Context.STORAGE_SERVICE);
    try {
        String[] volumes = (String[]) sm.getClass().getMethod("getVolumePaths").invoke(sm);
        if (volumes != null && volumes.length > 0) {
            pathList.addAll(Arrays.asList(volumes));
        }
    } catch (Exception e) {
        L.e(e);
    }
    if (pathList.size() == 0 && Environment.getExternalStorageDirectory() != null) {
        pathList.add(Environment.getExternalStorageDirectory().getAbsolutePath());
    }
    for (String path : pathList) {
        findCompilations(new File(path), 0);
        if (isCancelled()) {
            break;
        }
    }
    return compilations;
}
 
开发者ID:wikimedia,项目名称:apps-android-wikipedia,代码行数:24,代码来源:CompilationSearchTask.java

示例14: getInternalStorageSize

import android.os.storage.StorageManager; //导入依赖的package包/类
public static long getInternalStorageSize(Context context) {
    long j = 0;
    try {
        String[] paths = (String[]) StorageManager.class.getMethod("getVolumePaths", new Class[0]).invoke((StorageManager) context.getSystemService("storage"), new Object[0]);
        if (paths != null && paths.length >= 1) {
            StatFs statFs = new StatFs(paths[0]);
            j = ((((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / 1024) / 1024;
        }
    } catch (Exception e) {
        LogTool.e(TAG, "getInternalStorageSize. " + e.toString());
    }
    return j;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:DeviceUtils.java

示例15: getExternalStorageSize

import android.os.storage.StorageManager; //导入依赖的package包/类
public static long getExternalStorageSize(Context context) {
    long j = 0;
    try {
        String[] paths = (String[]) StorageManager.class.getMethod("getVolumePaths", new Class[0]).invoke((StorageManager) context.getSystemService("storage"), new Object[0]);
        if (paths != null && paths.length >= 2) {
            StatFs statFs = new StatFs(paths[1]);
            j = ((((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / 1024) / 1024;
        }
    } catch (Exception e) {
        LogTool.e(TAG, "getExternalStorageSize. " + e.toString());
    }
    return j;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:DeviceUtils.java


注:本文中的android.os.storage.StorageManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。