List of usage examples for android.content.res AssetManager open
public @NonNull InputStream open(@NonNull String fileName) throws IOException
From source file:com.bnrc.util.AbFileUtil.java
/** * ??sset?.//from w ww .ja v a2s .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:mr.robotto.ApplicationTest.java
public void testLoaders() { Context context = getContext(); AssetManager am = context.getAssets(); try {//from w w w. j a v a 2 s .co m InputStream stream = am.open("kingVer3.json"); JSONObject drac = (JSONObject) new JSONTokener(MrStreamReader.read(stream)).nextValue(); /*MrObjectLoader loader = new MrObjectLoader(drac); MrSceneData ob = (MrSceneData)loader.parse(); getRenderer().setScene(ob); getRenderer().model = new MrModelController((MrModelData)ob.getChildren().findByKey(0), new MrModelRender());*/ //MrRobottoJsonLoader loader = new MrRobottoJsonLoader(drac); //context1 = loader.parse(); //getRenderer().setScene((MrSceneData)context1.getObjectsData().findByKey("Scene")); //getRenderer().model = new MrModelController((MrModelData)context1.getObjectsData().findByKey("Cube"), new MrModelRender()); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } assertNotNull(null); }
From source file:com.commonsware.android.cp.v4file.FilesCPDemo.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); File f = new File(getFilesDir(), "test.pdf"); if (!f.exists()) { AssetManager assets = getResources().getAssets(); try {/* w ww . j a v a2 s .c om*/ copy(assets.open("test.pdf"), f); } catch (IOException e) { Log.e("FileProvider", "Exception copying from assets", e); } } Intent i = new Intent(Intent.ACTION_VIEW, FileProvider.getUriForFile(this, AUTHORITY, f)); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(i); finish(); }
From source file:com.ruenzuo.pokeffective.activities.InfoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.info_activity); getActionBar().setDisplayHomeAsUpEnabled(true); Uri data = getIntent().getData();//from www .j a va 2s . c o m if (data != null) { getActionBar().setTitle("License"); AssetManager assetManager = getAssets(); try { 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:org.anhonesteffort.flock.registration.HttpClientFactory.java
public DefaultHttpClient buildClient() throws RegistrationApiException { try {//from ww w .ja v a 2s. c om AssetManager assetManager = context.getAssets(); InputStream keyStoreInputStream = assetManager.open("flock.store"); KeyStore trustStore = KeyStore.getInstance("BKS"); trustStore.load(keyStoreInputStream, "owsflock".toCharArray()); SSLSocketFactory appSSLSocketFactory = new SSLSocketFactory(trustStore); DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry schemeRegistry = client.getConnectionManager().getSchemeRegistry(); Scheme httpsScheme = new Scheme("https", appSSLSocketFactory, 443); schemeRegistry.register(httpsScheme); return client; } catch (Exception e) { Log.e(getClass().getName(), "caught exception while constructing HttpClient client", e); throw new RegistrationApiException( "caught exception while constructing HttpClient client: " + e.toString()); } }
From source file:no.uio.skattejegeren.Json.java
public String getThemJSONs(final String jsonFileName) { String s = null;//from w w w.j a v a 2 s .co m AssetManager assetManager = asset; try { InputStream is = assetManager.open(jsonFileName); s = getWords(is); } catch (IOException e) { e.printStackTrace(); } return s; }
From source file:net.tacks_a.ankicard.fragment.HomeFragment.java
@Background protected void createInitData() { LogUtil.logDebug();//from w w w . j a va 2 s. c om try { if (mAnkiFolderModel.findAll().size() == 0) { mAnkiFolderModel.deleteAll(); mAnkiCardModel.deleteAll(); AssetManager assets = getResources().getAssets(); InputStream in = assets.open("init_data.csv"); InputStreamReader f = new InputStreamReader(in); mAnkiCardCsv.importAnkiCardCsv(f); } } catch (Exception e) { LogUtil.logError("create init data exception", e); } }
From source file:cn.org.eshow.framwork.util.AbFileUtil.java
/** * ???Asset?.//from ww w. j ava 2 s. com * * @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:cn.org.eshow.framwork.util.AbFileUtil.java
/** * ???Asset?.// w w w . ja v a 2s.co 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.micro.utils.F.java
/** * ???Asset?.//from w w w . j a v a 2s. co 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) { L.D("?" + e.getMessage()); } return bit; }