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


Java StorageVolume类代码示例

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


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

示例1: AppPagerAdapter

import android.os.storage.StorageVolume; //导入依赖的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

示例2: requestPermission

import android.os.storage.StorageVolume; //导入依赖的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

示例3: getStorageDirectories

import android.os.storage.StorageVolume; //导入依赖的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

示例4: getVolumeListApi24

import android.os.storage.StorageVolume; //导入依赖的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

示例5: printStorageVolumeMethods

import android.os.storage.StorageVolume; //导入依赖的package包/类
private static void printStorageVolumeMethods(Context context){
    try {
        StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        Method method = StorageManager.class.getMethod("getVolumeList");
        StorageVolume[] storageVolumes = (StorageVolume[]) method.invoke(storageManager);
        System.out.println("storageVolumes : " + storageVolumes.length);
        Method[] methods = storageVolumes[0].getClass().getMethods();
        for(Method m : methods){
            System.out.println("storageVolumes : methodName = " + m.getName() + " methodParams = " + getParams(m.getParameterTypes()) + " returnType = " + m.getReturnType().getSimpleName());
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:jiajunhui,项目名称:FileBase,代码行数:15,代码来源:StorageEngine.java

示例6: getStorageVolumes

import android.os.storage.StorageVolume; //导入依赖的package包/类
public static StorageVolume[] getStorageVolumes(Context context){
    StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
    try {
        Method method = StorageManager.class.getMethod("getVolumeList");
        return (StorageVolume[]) method.invoke(storageManager);
    }catch (Exception e){
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jiajunhui,项目名称:FileBase,代码行数:11,代码来源:StorageEngine.java

示例7: formatSDcard

import android.os.storage.StorageVolume; //导入依赖的package包/类
public static void formatSDcard(Context context) {
    StorageManager storageManager = StorageManager.from(context);
    final StorageVolume[] storageVolumes = storageManager.getVolumeList();

    Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY);
    intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
    intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, storageVolumes[1]);
    context.startService(intent);
}
 
开发者ID:rockcarry,项目名称:CameraDVR,代码行数:10,代码来源:SdcardManager.java

示例8: getStorageList

import android.os.storage.StorageVolume; //导入依赖的package包/类
public static List<Storage> getStorageList(Context context){
    List<Storage> result = new ArrayList<>();
    StorageVolume[] storageVolumes = getStorageVolumes(context);
    if(storageVolumes==null || storageVolumes.length<=0)
        return result;
    StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
    try {
        Storage storage;
        Method invokeMethod;
        for(int i=0;i<storageVolumes.length;i++){
            invokeMethod = storageVolumes[i].getClass().getMethod("getState");
            if(Environment.MEDIA_MOUNTED.equals(invokeMethod.invoke(storageVolumes[i]).toString())){
                storage = new Storage();
                //getDescriptionMethod = storageVolumes[i].getClass().getMethod("getDescription",Context.class);
                //allowMassStorageMethod = storageVolumes[i].getClass().getMethod("allowMassStorage");
                //isRemovableMethod = storageVolumes[i].getClass().getMethod("isRemovable");
                invokeMethod = storageVolumes[i].getClass().getMethod("getPath");
                String path = (String) invokeMethod.invoke(storageVolumes[i]);
                //set storage path
                storage.setPath(path);
                //set storage description
                invokeMethod = storageVolumes[i].getClass().getMethod("getDescription",Context.class);
                storage.setDescription((String) invokeMethod.invoke(storageVolumes[i],context));
                //set storage is removable
                invokeMethod = storageVolumes[i].getClass().getMethod("isRemovable");
                storage.setRemovableStorage((Boolean) invokeMethod.invoke(storageVolumes[i]));
                //set storage is allowMassStorage
                invokeMethod = storageVolumes[i].getClass().getMethod("allowMassStorage");
                storage.setAllowMassStorage((boolean) invokeMethod.invoke(storageVolumes[i]));
                //set storage is emulate
                invokeMethod = storageVolumes[i].getClass().getMethod("isEmulated");
                storage.setEmulated((boolean) invokeMethod.invoke(storageVolumes[i]));
                //set storage is primary
                invokeMethod = storageVolumes[i].getClass().getMethod("isPrimary");
                storage.setPrimary((boolean) invokeMethod.invoke(storageVolumes[i]));
                //set storage lowBytes limit
                invokeMethod = StorageManager.class.getMethod("getStorageLowBytes",File.class);
                storage.setLowBytesLimit((Long) invokeMethod.invoke(storageManager,new File(path)));
                //set storage fullBytes limit
                invokeMethod = StorageManager.class.getMethod("getStorageFullBytes",File.class);
                storage.setFullBytesLimit((Long) invokeMethod.invoke(storageManager,new File(path)));
                //set storage total size and available size
                long[] sizeInfo = getStorageSizeInfo(path);
                storage.setTotalSize(sizeInfo[0]);
                storage.setAvailableSize(sizeInfo[1]);
                result.add(storage);
            }

        }
    }catch (Exception e){
        e.printStackTrace();
    }

    return result;
}
 
开发者ID:jiajunhui,项目名称:FileBase,代码行数:56,代码来源:StorageEngine.java

示例9: checkStoragePermission

import android.os.storage.StorageVolume; //导入依赖的package包/类
static boolean checkStoragePermission(Fragment fragment) {
    if (Build.VERSION.SDK_INT < 23) {
        // runtime permissions not supported
        return false;
    }

    final Context context = fragment.getActivity();
    final String prefName = context.getString(R.string.download_dir_pref);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final String dDir = prefs.getString(prefName, "");

    try {
        if (Build.VERSION.SDK_INT >= 24) {
            if (!TextUtils.isEmpty(dDir)) {
                final File file = new File(dDir);
                final StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
                final StorageVolume sv = sm.getStorageVolume(file);
                if (sv == null || !Environment.MEDIA_MOUNTED.equals(sv.getState())) {
                    return false;
                }
            }
        } else {
            // use old-fashioned stat() check
            try {
                final File primaryStorage = Environment.getExternalStorageDirectory();
                if (primaryStorage != null) {
                    final StructStat dirStat = Os.stat(dDir);
                    final StructStat primaryStat = Os.stat(primaryStorage.getAbsolutePath());
                    if (dirStat.st_dev != primaryStat.st_dev) {
                        // the directory is not on primary external storage, bail
                        return false;
                    }
                }
            } catch (Exception ignored) {
            }
        }

        if (context.checkSelfPermission(WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            fragment.requestPermissions(new String[] { WRITE_EXTERNAL_STORAGE }, R.id.req_file_permission);
            return true;
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:chdir,项目名称:aria2-android,代码行数:48,代码来源:PermissionHelper.java

示例10: Api24StorageVolumeImpl

import android.os.storage.StorageVolume; //导入依赖的package包/类
private Api24StorageVolumeImpl(String path, StorageVolume volume) {
    mPath = path;
    mStorageVolume = volume;
}
 
开发者ID:AlexMofer,项目名称:ProjectX,代码行数:5,代码来源:AMStorageManagerCompat.java


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