List of usage examples for android.content.res AssetManager open
public @NonNull InputStream open(@NonNull String fileName) throws IOException
From source file:com.hoho.android.usbserial.examples.SerialConsoleActivity.java
void svmInit() throws Exception { SVMRecognition.numberOfDataitems = 2 * NUMBER_OF_INPUTS - 1; SVMLevelRecognition.numberOfDataitems = 2 * NUMBER_OF_INPUTS - 1; svml = new SVMLevelRecognition(); AssetManager assetManager = getAssets(); classifierSVML = (Classifier) SerializationHelper.read(assetManager.open(SVMLevelRecognition.modelPath)); svml.init();//from w ww .java 2 s . co m svm = new SVMRecognition(); classifierSVMH = (Classifier) SerializationHelper.read(assetManager.open(SVMRecognition.modelPath)); svm.init(); if (recognize) { SVMGestureRecognition.numberOfStates = numberOfGestures; SVMGestureRecognition.numberOfDataitems = numberOfGuestureInputs; svmg = new SVMGestureRecognition(); classifierSVMG = (Classifier) SerializationHelper .read(assetManager.open(SVMGestureRecognition.modelPath)); // should be called after training generation svmg.init(); } }
From source file:net.bible.service.readingplan.ReadingPlanDao.java
private synchronized Properties getPlanProperties(String planCode) { if (!planCode.equals(cachedPlanCode)) { Resources resources = BibleApplication.getApplication().getResources(); AssetManager assetManager = resources.getAssets(); String filename = planCode + DOT_PROPERTIES; // Read from the /assets directory Properties properties = new Properties(); InputStream inputStream = null; try {/*from w w w. ja v a2 s . c o m*/ // check to see if a user has created his own reading plan with this name File userReadingPlanFile = new File(USER_READING_PLAN_FOLDER, filename); boolean isUserPlan = userReadingPlanFile.exists(); if (!isUserPlan) { inputStream = assetManager.open(READING_PLAN_FOLDER + File.separator + filename); } else { inputStream = new FileInputStream(userReadingPlanFile); } properties.load(inputStream); Log.d(TAG, "The properties are now loaded"); Log.d(TAG, "properties: " + properties); // cache it so we don't constantly reload the properties cachedPlanCode = planCode; cachedPlanProperties = properties; } catch (IOException e) { System.err.println("Failed to open reading plan property file"); e.printStackTrace(); } finally { IOUtil.close(inputStream); } } return cachedPlanProperties; }
From source file:com.bellman.bible.service.readingplan.ReadingPlanDao.java
private synchronized Properties getPlanProperties(String planCode) { if (!planCode.equals(cachedPlanCode)) { Resources resources = CurrentActivityHolder.getInstance().getApplication().getResources(); AssetManager assetManager = resources.getAssets(); String filename = planCode + DOT_PROPERTIES; // Read from the /assets directory Properties properties = new Properties(); InputStream inputStream = null; try {/*from w w w. j a va 2 s . com*/ // check to see if a user has created his own reading plan with this name File userReadingPlanFile = new File(USER_READING_PLAN_FOLDER, filename); boolean isUserPlan = userReadingPlanFile.exists(); if (!isUserPlan) { inputStream = assetManager.open(READING_PLAN_FOLDER + File.separator + filename); } else { inputStream = new FileInputStream(userReadingPlanFile); } properties.load(inputStream); Log.d(TAG, "The properties are now loaded"); Log.d(TAG, "properties: " + properties); // cache it so we don't constantly reload the properties cachedPlanCode = planCode; cachedPlanProperties = properties; } catch (IOException e) { System.err.println("Failed to open reading plan property file"); e.printStackTrace(); } finally { IOUtil.close(inputStream); } } return cachedPlanProperties; }
From source file:joshuamgoodwin.gmail.com.ohiolegalaidassistant.MainActivity.java
private void CopyAssets(String fileName) { AssetManager am = getAssets(); InputStream in = null;/*from ww w. j a v a 2 s .c o m*/ OutputStream out = null; File file = new File(getFilesDir(), fileName); try { in = am.open(fileName); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; out.close(); out = null; } catch (Exception e) { Log.e("tag", e.getMessage()); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/" + fileName), "application/pdf"); startActivity(intent); }
From source file:org.zywx.wbpalmstar.plugin.inputtextfieldview.ACEInputTextFieldView.java
/** * For loading smileys from assets// w w w .j av a 2 s . c om */ private Bitmap getBitmap(String path) { AssetManager mngr = this.getContext().getAssets(); InputStream in = null; try { in = mngr.open(path); } catch (Exception e) { e.printStackTrace(); } Bitmap temp = BitmapFactory.decodeStream(in, null, null); return temp; }
From source file:de.baumann.thema.RequestActivity.java
private void parseXML() { try {//from w w w .j ava 2s. c o m XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance(); XmlPullParser myparser = xmlFactoryObject.newPullParser(); AssetManager am = context.getAssets(); InputStream inputStream = am.open(appfilter_path); myparser.setInput(inputStream, null); int activity = myparser.getEventType(); while (activity != XmlPullParser.END_DOCUMENT) { String name = myparser.getName(); switch (activity) { case XmlPullParser.START_TAG: break; case XmlPullParser.END_TAG: if (name.equals("item")) { try { String tmp_act = myparser.getAttributeValue(null, "component").split("/")[1]; String t_activity = tmp_act.substring(0, tmp_act.length() - 1); String tmp_pack = myparser.getAttributeValue(null, "component").split("/")[0]; String t_package = tmp_pack.substring(14, tmp_pack.length()); list_activities.add(t_package + "/" + t_activity); if (DEBUG) Log.v(TAG, "Added Styled App: \"" + t_package + "/" + t_activity + "\""); } catch (ArrayIndexOutOfBoundsException ignored) { } } break; } activity = myparser.next(); } } catch (IOException exIO) { handler.sendEmptyMessage(2); } //Show toast when there's no appfilter.xml in assets catch (XmlPullParserException ignored) { } }
From source file:cycronix.CTandroid.CTAserver.java
private void copyAssets() { AssetManager assetManager = getApplicationContext().getAssets(); String[] files = null;/* ww w.j a v a 2s. com*/ try { files = assetManager.list(resourceFolder); // folder name } catch (Exception e) { Log.e(TAG, "ERROR: " + e.toString()); } File directory = new File(Environment.getExternalStorageDirectory() + "/" + resourceFolder); directory.mkdirs(); for (int i = 0; i < files.length; i++) { try { InputStream in = assetManager.open("CTweb/" + files[i]); OutputStream out = new FileOutputStream( Environment.getExternalStorageDirectory() + "/" + resourceFolder + "/" + files[i]); byte[] buffer = new byte[65536]; int read; while ((read = in.read(buffer)) > 0) out.write(buffer, 0, read); in.close(); out.flush(); out.close(); Log.d(TAG, "Asset file copied to SD card: " + files[i]); } catch (Exception e) { Log.e(TAG, "ERROR: " + e.toString()); } } }
From source file:interactivespaces.controller.android.InteractiveSpacesFrameworkAndroidBootstrap.java
/** * @param ctxt/*w w w.ja va 2s. c om*/ * @param bundleList * @param jars * @throws BundleException */ private void startBundles(AssetManager assetManager, BundleContext ctxt, List<Bundle> bundleList, List<String> jars, boolean start) throws BundleException { for (String bundleFile : jars) { try { Bundle b = ctxt.installBundle(bundleFile, assetManager.open(bundleFile)); bundleList.add(b); bundles.add(b); jarToBundle.put(bundleFile.substring(bundleFile.indexOf('/') + 1), b); System.out.format("Added bundle file %s with ID %d\n", bundleFile, b.getBundleId()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // Start all installed non-fragment bundles. for (final Bundle bundle : bundleList) { if (!isFragment(bundle)) { if (start) startBundle(bundle); } } }
From source file:interactivespaces.controller.android.InteractiveSpacesFrameworkAndroidBootstrap.java
/** * Copy an asset file./*from w w w . j av a 2 s . co m*/ * * @param inputStream * the input stream for the asset * @param outputFile * where the file should be copied * @param assetManager * TODO */ private void copyAssetFile(String input, File outputFile, AssetManager assetManager) { System.out.format("Copying %s to %s\n", input, outputFile); byte buf[] = new byte[1024]; int len; FileOutputStream fos = null; InputStream inputStream = null; try { inputStream = assetManager.open(input); fos = new FileOutputStream(outputFile); while ((len = inputStream.read(buf)) != -1) { fos.write(buf, 0, len); } fos.flush(); } catch (IOException e) { } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { // Don't care } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // Don't care } } } }
From source file:org.loon.framework.android.game.LGameActivity.java
/** * Asset?//from w ww .ja v a 2 s . c om * * @param fileName * @return * @throws IOException */ public InputStream openAssetResource(String fileName) throws IOException { AssetManager assetmanager = getAssets(); boolean flag = fileName.startsWith("/"); String file; if (flag) { file = fileName.substring(1); } else { file = fileName; } return assetmanager.open(file); }