android获取assert资源文件

public List getAssetPicPath(Context context) {
        AssetManager am = context.getAssets();
        String[] path = null;
        try {
            path = am.list("");  // ""获取所有,填入目录获取该目录下所有资源
        } catch (IOException e) {
            e.printStackTrace();
        }
        List pciPaths = new ArrayList<>();
        for (int i = 0; i < path.length; i++) {
            if ((path[i].endsWith(".png") || path[i].endsWith(".jpg")) && path[i].startsWith("sy")) {  // 根据图片特征找出图片
                pciPaths.add(path[i]);
            }
        }
        return pciPaths;
    }
List assetPicPath = getAssetPicPath(MainActivity.this);//获取图片
System.out.println("图片一共有:"+assetPicPath.size()+"张");

显示图片

public final String PATH_HEAD = "file:///android_asset/";//在Glide中显示assets中的图片需要在图片名称前加上“file:///android_asset/”。
Glide.with(MainActivity.this).load(PATH_HEAD + assetPicPath.get(random.nextInt(x))).into(sy1);

 

你可能感兴趣的:(android)