V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
a624842184
V2EX  ›  Android

求助 android 盒子获取外置 SD 卡的路径问题,盒子是 7.1 的安卓系统

  •  
  •   a624842184 · Jul 24, 2020 · 12111 views
    This topic created in 2112 days ago, the information mentioned may be changed or developed.
    最近写一个测试机顶盒的 APK,需求是播放外置 SD 卡中的视频。
    现在有的手机用 Environment.getExternalStorageDirectory().getAbsolutePath();这个方法获取到的是内置存储的路径。
    private static String getStoragePath(Context mContext, boolean is_removale) {

    StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
    Class<?> storageVolumeClazz = null;
    try {
    storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
    Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
    Method getPath = storageVolumeClazz.getMethod("getPath");
    Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
    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);
    boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
    if (is_removale == removable) {
    return path;
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return null;
    }
    我百度了这个获取外置 SD 卡的方法,放在手机上面测试可以获取到外置 SD 卡的路径,但是放在机顶盒就获取不到了!
    机顶盒下了一个 es 文件管理器也是可以看到外置 SD 卡的路径的,所以说应该是可以获取到的。
    但是**的就是不知道怎么获取了,折腾了一天了。
    求大神指点!
    2 replies    2020-07-24 23:31:43 +08:00
    TanMusong
        1
    TanMusong  
       Jul 24, 2020
    Context.getExternalFilesDirs(Environment.MEDIA_MOUNTED);?
    nicocho
        2
    nicocho  
       Jul 24, 2020
    adb shell 命令 ls 下看看呢?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3206 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 00:28 · PVG 08:28 · LAX 17:28 · JFK 20:28
    ♥ Do have faith in what you're doing.