Java Code Examples for android.content.res.AssetManager#list()
The following examples show how to use
android.content.res.AssetManager#list() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PuBuActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@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(); } }
Example 2
Source File: UpgradeFragment.java From misound with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: BookPageFactory.java From eBook with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: HUDNative.java From screenstandby with GNU General Public License v2.0 | 6 votes |
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); } }
Example 5
Source File: ChangeBackgroundFragment.java From CoolWeather with Apache License 2.0 | 6 votes |
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(); } }
Example 6
Source File: DataHelper.java From Field-Book with GNU General Public License v2.0 | 6 votes |
/** * 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); } }
Example 7
Source File: EAdaptJniTask.java From appcan-android with GNU Lesser General Public License v3.0 | 6 votes |
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; }
Example 8
Source File: XWalkWebViewEngine.java From cordova-crosswalk-engine with Apache License 2.0 | 6 votes |
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); } }
Example 9
Source File: CopyFilesFromAssets.java From android-port with GNU General Public License v3.0 | 6 votes |
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) { } }
Example 10
Source File: AsyncDataRetriever.java From Android-Material-Icons with Apache License 2.0 | 6 votes |
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(); } } }
Example 11
Source File: FileHelper.java From gdx-pd with Apache License 2.0 | 6 votes |
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); } } }
Example 12
Source File: BaseUtility.java From LitePal with Apache License 2.0 | 6 votes |
/** * 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; }
Example 13
Source File: ExternalStorage.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); } }
Example 14
Source File: ReadStyleActivity.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
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); }
Example 15
Source File: TutorialView.java From GestureTutorial with Apache License 2.0 | 5 votes |
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); } }
Example 16
Source File: FixedPredictionTest.java From pasm-yolov3-Android with GNU General Public License v3.0 | 5 votes |
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); }
Example 17
Source File: ModelListActivity.java From LitePal with Apache License 2.0 | 5 votes |
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); }
Example 18
Source File: BasicMediaPlayerTestCaseBase.java From android-openslmediaplayer with Apache License 2.0 | 5 votes |
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); } }
Example 19
Source File: SampleChooserActivity.java From ExoPlayer-Offline with Apache License 2.0 | 5 votes |
@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); }
Example 20
Source File: AssetsUtils.java From HtmlNative with Apache License 2.0 | 4 votes |
public static String[] allFiles(Context context) throws IOException { AssetManager manager = context.getAssets(); return manager.list(""); }