use of android.content.res.AssetManager in project BlogSource by TeachCourse.
the class MainActivity method getFromAssetsPath.
/**
* 读取assets指定的xml文件,返回List
* @param fileName 文件名称
* @return List
*/
public List getFromAssetsPath(String fileName) {
InputStream is = null;
AssetManager manager = getAssets();
try {
is = manager.open(fileName);
List list = NewsService.getNewsBean(is);
Message msg = new Message();
msg.obj = list;
msg.what = 0x110;
handler.sendMessage(msg);
return list;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
use of android.content.res.AssetManager in project MifareClassicTool by ikarus23.
the class MainMenu method copyStdKeysFilesIfNecessary.
/**
* Copy the standard key files ({@link Common#STD_KEYS} and
* {@link Common#STD_KEYS_EXTENDED}) form assets to {@link Common#KEYS_DIR}.
* Key files are simple text files. Any plain text editor will do the trick.
* All key and dump data from this App is stored in
* getExternalStoragePublicDirectory(Common.HOME_DIR) to remain
* there after App uninstallation.
* @see Common#KEYS_DIR
* @see Common#HOME_DIR
* @see Common#copyFile(InputStream, OutputStream)
*/
private void copyStdKeysFilesIfNecessary() {
File std = Common.getFileFromStorage(Common.HOME_DIR + "/" + Common.KEYS_DIR + "/" + Common.STD_KEYS);
File extended = Common.getFileFromStorage(Common.HOME_DIR + "/" + Common.KEYS_DIR + "/" + Common.STD_KEYS_EXTENDED);
AssetManager assetManager = getAssets();
if (!std.exists()) {
// Copy std.keys.
try {
InputStream in = assetManager.open(Common.KEYS_DIR + "/" + Common.STD_KEYS);
OutputStream out = new FileOutputStream(std);
Common.copyFile(in, out);
in.close();
out.flush();
out.close();
} catch (IOException e) {
Log.e(LOG_TAG, "Error while copying 'std.keys' from assets " + "to external storage.");
}
}
if (!extended.exists()) {
// Copy extended-std.keys.
try {
InputStream in = assetManager.open(Common.KEYS_DIR + "/" + Common.STD_KEYS_EXTENDED);
OutputStream out = new FileOutputStream(extended);
Common.copyFile(in, out);
in.close();
out.flush();
out.close();
} catch (IOException e) {
Log.e(LOG_TAG, "Error while copying 'extended-std.keys' " + "from assets to external storage.");
}
}
}
use of android.content.res.AssetManager in project devbricks by dailystudio.
the class BitmapUtils method loadAssetBitmap.
public static Bitmap loadAssetBitmap(Context context, String assetFile) {
AssetManager assetManager = context.getAssets();
if (assetManager == null) {
return null;
}
if (TextUtils.isEmpty(assetFile)) {
return null;
}
InputStream istream = null;
Bitmap bitmap = null;
try {
istream = assetManager.open(assetFile);
if (istream != null) {
bitmap = BitmapFactory.decodeStream(istream);
}
} catch (OutOfMemoryError e) {
Logger.warn("could not decode asset bitmap: %s", assetFile, e.toString());
bitmap = null;
} catch (IOException e) {
Logger.warn("could not decode asset bitmap: %s", assetFile, e.toString());
bitmap = null;
} finally {
try {
if (istream != null) {
istream.close();
}
} catch (IOException e) {
}
}
return bitmap;
}
use of android.content.res.AssetManager in project devbricks by dailystudio.
the class FileUtils method copyAssetFile.
public static boolean copyAssetFile(Context context, String assetFile, String dstFile) throws IOException {
if (context == null || assetFile == null || dstFile == null) {
return false;
}
final AssetManager asstmgr = context.getAssets();
if (asstmgr == null) {
return false;
}
InputStream istream = asstmgr.open(assetFile);
if (istream == null) {
return false;
}
FileOutputStream ostream = new FileOutputStream(dstFile);
return ResourcesUtils.copyToFile(istream, ostream);
}
use of android.content.res.AssetManager in project devbricks by dailystudio.
the class FileUtils method getAssetFileContent.
public static String getAssetFileContent(Context context, String file) throws IOException {
if (context == null || file == null) {
return null;
}
final AssetManager asstmgr = context.getAssets();
if (asstmgr == null) {
return null;
}
final String encoding = detectFileEncoding(asstmgr.open(file));
Logger.debug("encoding = %s", encoding);
InputStream istream = asstmgr.open(file);
if (istream == null) {
return null;
}
return getFileContent(istream, encoding);
}
Aggregations