List of usage examples for android.content.res AssetManager open
public @NonNull InputStream open(@NonNull String fileName) throws IOException
From source file:com.jungle.base.utils.MiscUtils.java
public static String getAssetContent(String path) { StringBuilder builder = new StringBuilder(); AssetManager mgr = BaseApplication.getApp().getAssets(); try {/* www.j a va2s .c om*/ InputStreamReader reader = new InputStreamReader(mgr.open(path)); BufferedReader buffReader = new BufferedReader(reader); String line = ""; while ((line = buffReader.readLine()) != null) { builder.append(line); builder.append("\r\n"); } buffReader.close(); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
From source file:edu.polyu.screamalert.SoundProcessing.java
private static void executeMainLoop(Context context) throws Exception { try {/* ww w . j a v a 2 s .c o m*/ prepareTempFile(); os = new FileOutputStream(getTempFilename()); } catch (FileNotFoundException e) { e.printStackTrace(); } paraFile = Exchanger.SVM_PARA_FILE; int dim = numMfcc * 3 + 2; // (=38) MFCC+dMFCC+ddMFCC+jitter+shimmer without energy, dEnergy, and ddEnergy svmd = new SVMdetector(dim * 2, Config.SVM_TYPE, 0.0); // Create an SVM detector, input vector contains both mean and stddev vectors AssetManager assetManager = context.getResources().getAssets(); // Use AsstManager to load SVM detector parameters into memory svmd.createSVMdetector(assetManager.open(paraFile)); // Load parameter file to SVM detector while (isRecording) { shortData = new short[recordBufferSize / 2]; // Main loop of sound detector if (recorder == null) { System.out.println("Recorder: null recorder in executeMainLoop"); } else { recorder.read(shortData, 0, recordBufferSize / 2); // Read audio and fill in shortData[] buffer in short int format bufferedShortData.add(shortData); // Add to ArrayList for processing handler.post(processData); // Start processing data in bufferedShortData SoundProcessingActivity.waveformView.updateAudioData(shortData); // Display current waveform } } }
From source file:com.dream.library.utils.AbFileUtil.java
/** * ???Asset?./*from w ww . j a va2 s. c o m*/ * * @param context the mContext * @param fileName the file name * @return Bitmap */ public static Bitmap getBitmapFromAsset(Context context, String fileName) { Bitmap bit = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); bit = BitmapFactory.decodeStream(is); } catch (Exception e) { AbLog.e("?" + e.getMessage()); } return bit; }
From source file:com.dream.library.utils.AbFileUtil.java
/** * ???Asset?./*from w w w . j ava2 s . c o m*/ * * @param context the mContext * @param fileName the file name * @return Drawable */ public static Drawable getDrawableFromAsset(Context context, String fileName) { Drawable drawable = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); drawable = Drawable.createFromStream(is, null); } catch (Exception e) { AbLog.e("?" + e.getMessage()); } return drawable; }
From source file:most.voip.api.Utils.java
/** * Copy the specified resource file from the assets folder into the "files dir" of this application, so that this resource * can be opened by the Voip Lib by providing it the absolute path of the copied resource * @param ctx The application context/*from ww w . ja v a 2s . c o m*/ * @param assetPath The path of the resource (e.g on_hold.wav or sounds/on_hold.wav) * @return the absolute path of the copied resource, or null if no file was copied. */ public static String getResourcePathByAssetCopy(Context ctx, String assetSubFolder, String fileToCopy) { Log.d(TAG, "getResourcePathByAssetCopy on folder *" + assetSubFolder + "* for file:" + fileToCopy); AssetManager assetManager = ctx.getAssets(); String[] files = null; String filename = null; try { files = assetManager.list(assetSubFolder); Log.d(TAG, "Found " + files.length + " files"); if (files.length > 0) { for (String f : files) { Log.d(TAG, "Found resource:" + f); if (f == null) continue; if (f.equals(fileToCopy)) { filename = f; break; } } Log.d(TAG, "Found:" + filename); if (filename == null) return null; InputStream in = null; OutputStream out = null; try { in = assetManager.open(filename); File outFile = new File(ctx.getExternalFilesDir(null), filename); Log.d(TAG, "Copying asset to " + outFile.getAbsolutePath()); out = new FileOutputStream(outFile); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; return outFile.getAbsolutePath(); } catch (IOException e) { Log.e(TAG, "Failed to copy asset file: " + filename, e); } } } catch (IOException e) { Log.e(TAG, "Failed to get asset file list.", e); } return null; }
From source file:com.ris.mobile.ecloud.util.AbFileUtil.java
/** * ???Asset?./* w w w. j av a2 s . c o m*/ * * @param context the context * @param fileName the file name * @return Bitmap */ public static Bitmap getBitmapFromAsset(Context context, String fileName) { Bitmap bit = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); bit = BitmapFactory.decodeStream(is); } catch (Exception e) { //AbLogUtil.d(AbFileUtil.class, "?"+e.getMessage()); } return bit; }
From source file:com.ris.mobile.ecloud.util.AbFileUtil.java
/** * ???Asset?./*from w ww.j a v a 2s . c o m*/ * * @param context the context * @param fileName the file name * @return Drawable */ public static Drawable getDrawableFromAsset(Context context, String fileName) { Drawable drawable = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); drawable = Drawable.createFromStream(is, null); } catch (Exception e) { //AbLogUtil.d(AbFileUtil.class, "?"+e.getMessage()); } return drawable; }
From source file:com.ruenzuo.babel.activities.LicensesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.licenses_activity_layout); ButterKnife.inject(this); AssetManager assetManager = getAssets(); try {// ww w . j a v a2 s . co m InputStream inputStream = assetManager.open("licenses/licenses.txt"); StringWriter stringWriter = new StringWriter(); IOUtils.copy(inputStream, stringWriter); String licenses = stringWriter.toString(); vwTextLicenses.setText(licenses); } catch (IOException e) { Toast.makeText(this, getString(R.string.error_while_loading_licenses), Toast.LENGTH_LONG).show(); } }
From source file:com.ruenzuo.through.activities.LicensesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.licenses_activity_layout); getActionBar().setDisplayHomeAsUpEnabled(true); AssetManager assetManager = getAssets(); try {//from w w w. j a v a2 s .co m InputStream inputStream = assetManager.open("licenses/licenses.txt"); StringWriter stringWriter = new StringWriter(); IOUtils.copy(inputStream, stringWriter); String licenses = stringWriter.toString(); TextView txtViewLicenses = (TextView) findViewById(R.id.txtViewLicenses); txtViewLicenses.setText(licenses); txtViewLicenses.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.bnrc.util.AbFileUtil.java
/** * ??sset?.//from w w w .j av a 2 s. c o m * * @param context the context * @param fileName the file name * @return Bitmap ? */ public static Bitmap getBitmapFromAsset(Context context, String fileName) { Bitmap bit = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); bit = BitmapFactory.decodeStream(is); } catch (Exception e) { AbLogUtil.d(AbFileUtil.class, "?" + e.getMessage()); } return bit; }