mobile CCTV,mobile surveillance,police body worn cameras

 forgetPW
 registerNow
search
view: 255|reply: 5
打印 prevThread nextThread

BL502客户自己APP切换到外部TF卡存储

[copyURL]

60

主题

1413

帖子

5805

积分

Moderator

Rank: 7Rank: 7Rank: 7

积分
5805
jumpTo
owner
poston 2023-10-12 16:06 | authorOnly 回帖奖励 |倒序浏览 |阅读模式
File externalFilesDir = Environment.getExternalStorageDirectory();
我插TF后,使用getExternalStorageDirectory数据目录依然是内部的TF卡,有办法存储到外部吗?

reply

使用道具 report

1

主题

311

帖子

1105

积分

vipMem

Rank: 6Rank: 6

积分
1105
sofa
poston 2023-10-12 16:12 | authorOnly
        public static List<StorageInfo> listAvaliableStorage(Context context) {
                storages = new ArrayList<StorageInfo>();
               
                StorageManager storageManager =  (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
                try {
                        Class<?>[] paramClasses = {};
                        Method getVolumeList = StorageManager.class.getMethod(
                                        "getVolumeList", paramClasses);
                        getVolumeList.setAccessible(true);
                        Object[] params = {};
                        Object[] invokes = (Object[]) getVolumeList.invoke(storageManager,
                                        params);
                        if (invokes != null) {
                                StorageInfo info = null;
                                for (int i = 0; i < invokes.length; i++) {
                                        Object obj = invokes[i];
                                        Method getPath = obj.getClass().getMethod("getPath",
                                                        new Class[0]);
                                        String path = (String) getPath.invoke(obj, new Object[0]);
                                        info = new StorageInfo(path);

                                        Method isRemovable = obj.getClass().getMethod(
                                                        "isRemovable", new Class[0]);
                                        String state = null;
                                        try {
                                                Method getVolumeState = StorageManager.class.getMethod(
                                                                "getVolumeState", String.class);
                                                state = (String) getVolumeState.invoke(storageManager,
                                                                info.path);
                                                info.state = state;
                                        } catch (Exception e) {
                                                e.printStackTrace();
                                        }
                                        if (info.isMounted()) {
                                                info.isRemoveable = ((Boolean) isRemovable.invoke(obj,
                                                                new Object[0])).booleanValue();
                                                storages.add(info);
                                        }
                                }
                        }
                } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e1) {
                        e1.printStackTrace();
                }
                sdCounts = storages.size();
                return storages;
        }
reply agree Against

使用道具 report

2

主题

5

帖子

20

积分

newBie

Rank: 1

积分
20
bench
poston 2023-10-12 16:24 | authorOnly
Arthur post on2023-10-12 16:12
public static List listAvaliableStorage(Context context) {
                storages = new ArrayList();
               

     info = new StorageInfo(path);
Call requires API level 31 (current min is 26): new android.app.appsearch.StorageInfo
reply agree Against

使用道具 report

2

主题

5

帖子

20

积分

newBie

Rank: 1

积分
20
ground
poston 2023-10-12 16:25 | authorOnly
cus6 post on2023-10-12 16:24
info = new StorageInfo(path);
Call requires API level 31 (current min is 26): new android.ap ...

BL502使用的Android8.1
reply agree Against

使用道具 report

2

主题

5

帖子

20

积分

newBie

Rank: 1

积分
20
5#
poston 2023-10-12 16:36 | authorOnly

public class StorageUtil {
    public static List<StorageVolume> listAvailableStorage(Context context) {
        ArrayList<StorageVolume> storageVolumes = new ArrayList<>();

        StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        if (storageManager != null) {
            StorageVolume[] volumes = storageManager.getStorageVolumes().toArray(new StorageVolume[0]);
            for (StorageVolume volume : volumes) {
                storageVolumes.add(volume);
            }
        }

        return storageVolumes;
    }
}

这个可以
reply agree Against

使用道具 report

1

主题

311

帖子

1105

积分

vipMem

Rank: 6Rank: 6

积分
1105
6#
poston 2023-10-12 16:42 | authorOnly
你获取到路径就行,这个StorageInfo是我们自己封装的类。
reply agree Against

使用道具 report

creditRule

QQ|wireless surveillance

GMT+8, 2024-5-4 02:38 , Processed in 0.065426 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

QuickReply backToTop BackToList