List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:Main.java
static public boolean copyAllAssertToCacheFolder(Context c) throws IOException { String[] files = c.getAssets().list("Devices"); String filefolder = c.getFilesDir().toString(); File devicefile = new File(filefolder + "/Devices/"); devicefile.mkdirs();// w w w. ja va 2 s. c om for (int i = 0; i < files.length; i++) { File devfile = new File(filefolder + "/Devices/" + files[i]); if (!devfile.exists()) { copyFileTo(c, "Devices/" + files[i], filefolder + "/Devices/" + files[i]); } } String[] filestr = devicefile.list(); for (int i = 0; i < filestr.length; i++) { Log.i("file", filestr[i]); } return true; }
From source file:Main.java
public static InputStream openAssetsFile(Context context, String assetfilePath) { InputStream is = null;/*from w w w . j av a2 s . c om*/ try { is = context.getAssets().open(assetfilePath); } catch (IOException e) { e.printStackTrace(); } return is; }
From source file:Main.java
/** * Get file from assets/*from w w w .j a v a 2 s .c om*/ * * @param context * @param fileName * @return * @throws IOException */ public static InputStream getFileFromAssets(Context context, String fileName) throws IOException { AssetManager am = context.getAssets(); return am.open(fileName); }
From source file:Main.java
private static Typeface getChronicaProRegular(Context context) { if (mChronicaProRegularFont == null) mChronicaProRegularFont = Typeface.createFromAsset(context.getAssets(), "fonts/ChronicaPro-Regular.otf"); return mChronicaProRegularFont; }
From source file:Main.java
public static String getProperty(String key, Context context) throws IOException { Properties properties = new Properties(); AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open("marvel.properties"); properties.load(inputStream);//w w w.jav a 2 s . c o m return properties.getProperty(key); }
From source file:Main.java
public static Bitmap getImageFromAssetsFile(Context context, String fileName) { Bitmap image = null;/*from w ww . j a v a 2 s .com*/ AssetManager am = context.getAssets(); InputStream is = null; try { is = am.open(fileName); image = BitmapFactory.decodeStream(is); return image; } catch (IOException e) { e.printStackTrace(); return image; } finally { if (is != null) { try { is.close(); is = null; } catch (IOException e) { e.printStackTrace(); } } } }
From source file:Main.java
/** * A method to load x.json files from assets folder and convert them * into a string.// w w w . j a v a 2s . co m * * @param c A contect * @param fileName The json file in assets folder which to load json data from * @return */ public static String loadJSONFromAsset(Context c, String fileName) { String json = null; try { InputStream is = c.getAssets().open(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); json = new String(buffer, "UTF-8"); } catch (IOException ex) { ex.printStackTrace(); return null; } return json; }
From source file:Main.java
public static String loadJSONFromAsset(Context context, String fileName) { String json = null;//from w w w . j a v a2s . co m try { InputStream is = context.getAssets().open(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); json = new String(buffer, "UTF-8"); } catch (IOException ex) { Log.d(TAG, "Exception Occurred : " + ex.getMessage()); return null; } return json; }
From source file:Main.java
public static Bitmap getBitmap(Context context, String url) { Bitmap bitmap = null;/* ww w . ja va2 s.c o m*/ try { bitmap = BitmapFactory.decodeStream(context.getAssets().open(url)); } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
/** * @param filePath example("text/text_1.txt") *///from w ww. j a va 2s .co m public static InputStreamReader getAssetsText(Context context, String filePath) { InputStreamReader reader = null; AssetManager assetManager = context.getAssets(); try { InputStream inputStream = assetManager.open(filePath); reader = new InputStreamReader(inputStream, "utf-8"); } catch (IOException e) { e.printStackTrace(); } return reader; }