android.content.res.AssetManager#list()源码实例Demo

下面列出了android.content.res.AssetManager#list() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-port   文件: CopyFilesFromAssets.java
public void copyFileOrDir(String path) {

		AssetManager assetManager = context.getAssets();
		String assets[] = null;
		try {
			assets = assetManager.list(path);
			if (assets.length == 0) {
				copyFile(path);
			} else {
				String fullPath = configsPath;
				File dir = new File(fullPath);
				if (!dir.exists())
					dir.mkdirs();
				for (int i = 0; i < assets.length; ++i) {
					copyFileOrDir(path + "/" + assets[i]);
				}
			}
		} catch (IOException ex) {

		}

	}
 
源代码2 项目: screenstandby   文件: HUDNative.java
private static void copyFileOrDir(String path, Context context) {
    try {
        AssetManager assetManager = context.getAssets();
        String assets[] = null;
        assets = assetManager.list(path);
        if (assets.length == 0) {
            copyFile(path,context);
        } else {
            String fullPath = "/data/data/" + context.getPackageName() + "/" + path;
            File dir = new File(fullPath);
            if (!dir.exists())
                dir.mkdir();
            for (int i = 0; i < assets.length; ++i) {
                copyFileOrDir(path + "/" + assets[i],context);
            }
        }
    } catch (IOException ex) {
        Log.e("tag", "I/O Exception", ex);
    }
}
 
源代码3 项目: CoolWeather   文件: ChangeBackgroundFragment.java
private void initBackgroundPic()
{
	AssetManager am = getActivity().getAssets();
	try {
		String[] drawableList = am.list("bkgs");
		mBgPicList = new ArrayList<BgPicEntity>();
		for (String path : drawableList) {
			BgPicEntity bg = new BgPicEntity();
			InputStream is = am.open("bkgs/" + path);
			Bitmap bitmap = BitmapFactory.decodeStream(is);
			bg.path = path;
			bg.bitmap = bitmap;
			mBgPicList.add(bg);
			is.close();
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	
}
 
源代码4 项目: Field-Book   文件: DataHelper.java
/**
 * V2 - Helper function to copy multiple files from asset to SDCard
 */
public void copyFileOrDir(String fullPath, String path) {
    AssetManager assetManager = context.getAssets();
    String assets[];

    try {
        assets = assetManager.list(path);

        if (assets.length == 0) {
            copyFile(fullPath, path);
        } else {
            File dir = new File(fullPath);

            if (!dir.exists())
                dir.mkdir();

            for (String asset : assets) {
                copyFileOrDir(fullPath, path + "/" + asset);
            }
        }
    } catch (IOException ex) {
        Log.e("Sample Data", "I/O Exception", ex);
    }
}
 
源代码5 项目: appcan-android   文件: EAdaptJniTask.java
private boolean doInBackground() {
    boolean ok = true;
    AssetManager asset = mContext.getAssets();
    try {
        File rootDir = new File(DeviceDirName + RootDirName);
        if (!rootDir.exists()) {
            rootDir.mkdir();
        }
        String[] fileList = asset.list(RootDirName);
        if (null != fileList) {
            for (String level : fileList) {
                String realPath = RootDirName + File.separator + level;
                if (isFile(realPath)) {
                    handleFile(asset, realPath);
                } else {
                    handleDirectory(asset, realPath);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        ok = false;
    }
    return ok;
}
 
private void loadExtensions() {
    AssetManager assetManager = cordova.getActivity().getAssets();
    String[] extList;
    try {
        Log.i(TAG, "Iterate assets/xwalk-extensions folder");
        extList = assetManager.list(XWALK_EXTENSIONS_FOLDER);
    } catch (IOException e) {
        Log.w(TAG, "Failed to iterate assets/xwalk-extensions folder");
        return;
    }

    for (String path : extList) {
        // Load the extension.
        Log.i(TAG, "Start to load extension: " + path);
        webView.getExtensionManager().loadExtension(XWALK_EXTENSIONS_FOLDER + File.separator + path);
    }
}
 
private void checkFirstLaunch() {
    if (mIconsDirectory.list().length == 0) {
        AssetManager manager = mContext.getAssets();
        try {
            for (String assetChild : manager.list("icons")) {

                String path = mContext.getFilesDir().getAbsolutePath() + MainActivity.ICONS_PATH +
                        File.separator + assetChild;

                Utils.writeFile(path, manager.open("icons/" + assetChild));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
源代码8 项目: gdx-pd   文件: FileHelper.java
public static void copyAssetFolder(AssetManager assetManager,
		String fromAssetPath, String toPath) throws IOException {
	String[] files = assetManager.list(fromAssetPath);
	new File(toPath).mkdirs();
	for (String file : files)
	{
		// try to copy file (will fail if its a directory)
		try
		{
			copyAsset(assetManager, fromAssetPath + "/" + file, toPath
					+ "/" + file);
		}
		catch(FileNotFoundException e)
		{
			copyAssetFolder(assetManager, fromAssetPath + "/" + file,
					toPath + "/" + file);
		}
	}
}
 
源代码9 项目: LitePal   文件: BaseUtility.java
/**
 * If the litepal.xml configuration file exists.
 * @return True if exists, false otherwise.
 */
public static boolean isLitePalXMLExists() {
    try {
        AssetManager assetManager = LitePalApplication.getContext().getAssets();
        String[] fileNames = assetManager.list("");
        if (fileNames != null && fileNames.length > 0) {
            for (String fileName : fileNames) {
                if (Const.Config.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) {
                    return true;
                }
            }
        }
    } catch (IOException e) {
    }
    return false;
}
 
源代码10 项目: OpenMapKitAndroid   文件: ExternalStorage.java
private static void copyAssetsFileOrDirToExternalStorage(Context context, String path) {
    AssetManager assetManager = context.getAssets();
    String assets[] = null;
    try {
        assets = assetManager.list(path);
        if (assets.length == 0) {
            copyAssetsFileToExternalStorage(context, path);
        } else {
            String fullPath = Environment.getExternalStorageDirectory() + "/" + APP_DIR + "/" + path;
            File dir = new File(fullPath);
            if (!dir.exists())
                dir.mkdir();
            for (int i = 0; i < assets.length; ++i) {
                copyAssetsFileOrDirToExternalStorage(context, path + "/" + assets[i]);
            }
        }
    } catch (IOException ex) {
        Log.e("tag", "I/O Exception", ex);
    }
}
 
源代码11 项目: eBook   文件: BookPageFactory.java
private void getFontFromAssets() {
    mTypefaceList.add(Typeface.DEFAULT);

    String[] fontNameList = null;
    AssetManager assetManager = mContext.getAssets();
    try {
        fontNameList = assetManager.list(FontPopup.FONTS);
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < fontNameList.length; i++) {

        String fontPath = FontPopup.FONTS + "/" + fontNameList[i];
        Typeface typeface = Typeface.createFromAsset(assetManager, fontPath);//根据路径得到Typeface
        mTypefaceList.add(typeface);
    }

}
 
源代码12 项目: misound   文件: UpgradeFragment.java
private String getUpgradeVersionFromAsset(){
    String versionName = "";
    try {
        //query local version
        AssetManager am = getActivity().getAssets();
        String[] files = am.list("dfu");
        for (String fileName : files) {
            if (fileName.endsWith(".ver")) {
                versionName = fileName.substring(0, fileName.lastIndexOf(".ver"));
            }
        }
    }catch (Exception e){
        e.printStackTrace();
    }
    return versionName;
}
 
源代码13 项目: Study_Android_Demo   文件: PuBuActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pubu_layout);
    puBuLayout = (PuBuLayout) findViewById(R.id.pubu_layout);
    //获取AssetManager
    AssetManager manager = getAssets();
    try {
        //获取Assets目录中的文件,得到文件名数组
        String[] images = manager.list("images");
        for(int i=0; i<images.length;i++){
            //向布局中添加Bitmap
            //把文件转换Bitmap
            InputStream in = manager.open("images/" + images[i]);
            Bitmap bitmap = BitmapFactory.decodeStream(in);
            puBuLayout.addImage(bitmap);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
源代码14 项目: ExoPlayer-Offline   文件: SampleChooserActivity.java
@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_chooser_activity);
    Intent intent = getIntent();
    String dataUri = intent.getDataString();
    String[] uris;
    if (dataUri != null) {
      uris = new String[] {dataUri};
    } else {
      ArrayList<String> uriList = new ArrayList<>();
      AssetManager assetManager = getAssets();
      try {
        for (String asset : assetManager.list("")) {
          if (asset.endsWith(".exolist.json")) {
//            uriList.add("asset:///" + asset);
          }else if(asset.endsWith(".exolist.new.json")){
            uriList.add("asset:///" + asset);
          }
        }
      } catch (IOException e) {
        Toast.makeText(getApplicationContext(), R.string.sample_list_load_error, Toast.LENGTH_LONG)
            .show();
      }
      uris = new String[uriList.size()];
      uriList.toArray(uris);
      Arrays.sort(uris);
    }
    SampleListLoader loaderTask = new SampleListLoader();
    loaderTask.execute(uris);
  }
 
protected void copyAllTestSoundsToStorage() throws IOException {
    String[] assets = null;
    AssetManager am = getContext().getAssets();
    File destBaseDir = getTempDir();

    assets = am.list(TESTSOUND_DIR);

    for (String asset : assets) {
        CommonTestCaseUtils.copyAssetFile(
                am, TESTSOUND_DIR + File.separator + asset,
                destBaseDir, false);
    }
}
 
源代码16 项目: LitePal   文件: ModelListActivity.java
private InputStream getInputStream() throws IOException {
	AssetManager assetManager = LitePalApplication.getContext().getAssets();
	String[] fileNames = assetManager.list("");
	if (fileNames != null && fileNames.length > 0) {
		for (String fileName : fileNames) {
			if (Const.Config.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) {
				return assetManager.open(fileName, AssetManager.ACCESS_BUFFER);
			}
		}
	}
	throw new ParseConfigurationFileException(
			ParseConfigurationFileException.CAN_NOT_FIND_LITEPAL_FILE);
}
 
源代码17 项目: pasm-yolov3-Android   文件: FixedPredictionTest.java
private Bitmap loadFirstImage() throws IOException {
    checkPermissions();
    Context testContext = InstrumentationRegistry.getInstrumentation().getContext();
    AssetManager assetManager = testContext.getAssets();

    String pathToImages = "images";
    String[] list = assetManager.list(pathToImages);
    return getBitmapFromTestAssets(list[0], pathToImages);
}
 
源代码18 项目: MyBookshelf   文件: ReadStyleActivity.java
void initList() {
    AssetManager am = context.getAssets();
    String[] path;
    try {
        path = am.list("bg");  //获取所有,填入目录获取该目录下所有资源
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    assetsFiles = new ArrayList<>();
    Collections.addAll(assetsFiles, path);
}
 
源代码19 项目: GestureTutorial   文件: TutorialView.java
static void displayFiles(final AssetManager mgr, final String path) {
	try {
		final String list[] = mgr.list(path);
		if (list != null) {
			for (int i = 0; i < list.length; ++i) {
				Log.v("Assets:", path + "/" + list[i]);
				displayFiles(mgr, path + "/" + list[i]);
			}
		}
	} catch (final IOException e) {
		Log.v("List error:", "can't list" + path);
	}

}
 
源代码20 项目: HtmlNative   文件: AssetsUtils.java
public static String[] allFiles(Context context) throws IOException {
    AssetManager manager = context.getAssets();
    return manager.list("");
}