本文整理汇总了Java中android.content.res.AssetManager.open方法的典型用法代码示例。如果您正苦于以下问题:Java AssetManager.open方法的具体用法?Java AssetManager.open怎么用?Java AssetManager.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.res.AssetManager
的用法示例。
在下文中一共展示了AssetManager.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyAssetsToSdCard
import android.content.res.AssetManager; //导入方法依赖的package包/类
private void copyAssetsToSdCard(String fileName, String filesDir) throws Exception
{
Context testContext = getContext().createPackageContext("de.yaacc.tests",
Context.CONTEXT_IGNORE_SECURITY);
AssetManager assets = testContext.getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(filesDir, fileName);
try
{
in = assets.open(fileName);
out = getContext().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e)
{
Log.e("tag", e.getMessage());
}
}
示例2: readAssetsJson
import android.content.res.AssetManager; //导入方法依赖的package包/类
/**
* 读取assets下的json数据
*
* @return
*/
private String readAssetsJson()
{
AssetManager assetManager = getActivity().getAssets();
try
{
InputStream is = assetManager.open("region.json");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
String str;
while ((str = br.readLine()) != null)
{
stringBuilder.append(str);
}
return stringBuilder.toString();
} catch (IOException e)
{
e.printStackTrace();
return null;
}
}
示例3: loadBundledAssets
import android.content.res.AssetManager; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
private void loadBundledAssets(List<MemeData.Font> fonts, List<MemeData.Image> images) {
AssetManager assetManager = _context.getAssets();
File config = new File(getBundledAssetsDir(_appSettings), MEMETASTIC_CONFIG_FILE);
config.delete();
try {
File cacheDir = getBundledAssetsDir(_appSettings);
if (cacheDir.exists() || cacheDir.mkdirs()) {
for (String assetFilename : assetManager.list("bundled")) {
InputStream is = assetManager.open("bundled/" + assetFilename);
byte[] data = FileUtils.readCloseBinaryStream(is);
FileUtils.writeFile(new File(cacheDir, assetFilename), data);
}
}
} catch (IOException ignored) {
}
}
示例4: writeVoicesFromAsset
import android.content.res.AssetManager; //导入方法依赖的package包/类
/**
* Write available voices from assets to internal storage
* @throws IOException
*/
private void writeVoicesFromAsset() throws IOException{
// File doesn't exist => Copy default file from asset
AssetManager am = getContext().getAssets();
InputStream in = am.open(getContext().getResources().getString(R.string.uri_voices_list));
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
// Read asset file
String line;
String content = "";
while ((line = reader.readLine()) != null)
content += line + "\n";
in.close();
// Write the asset file content to a new file into internal storage
File copy = new File(getContext().getFilesDir(), getContext().getResources().getString(R.string.uri_voices_list));
FileOutputStream os = new FileOutputStream(copy);
os.write(content.getBytes());
os.close();
}
示例5: Level2
import android.content.res.AssetManager; //导入方法依赖的package包/类
public Level2(PlayScreen ps, MainActivity act){
this.ps = ps;
try {
AssetManager assetManager = act.getAssets();
InputStream inputStream = assetManager.open("maps/map2.jpg");
map = BitmapFactory.decodeStream(inputStream);
mapEdge = BitmapFactory.decodeStream(assetManager.open("maps/map2edges.png"));
inputStream.close();
}catch(Exception e){
//dont care sorry
}
}
示例6: getImageFromAssetFile
import android.content.res.AssetManager; //导入方法依赖的package包/类
/**
* 从系统的asset中读取一张图片 . <br>
* @author liulongzhenhai 2012-8-1 下午5:21:12 <br>
* @param context 上下文
* @param fileName 文件相对路劲
* @param density Options.inDensity的设置,在一些情况下,需要制定.否则,会变形
* @return 返回图片
*/
public static Bitmap getImageFromAssetFile(final Context context, final String fileName, final int density) {
if (TextUtils.isEmpty(fileName)) {
return null;
}
Bitmap image = null;
try {
final AssetManager am = context.getAssets();
final InputStream is = am.open(fileName);
final Options o = new Options();
o.inDensity = density;
image = BitmapFactory.decodeStream(is, null, o);
is.close();
} catch (final Exception e) {
}
return image;
}
示例7: loadHosts
import android.content.res.AssetManager; //导入方法依赖的package包/类
private static void loadHosts(final Context context) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
AssetManager manager = context.getAssets();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(manager.open(FILE)));
String line;
while ((line = reader.readLine()) != null) {
hosts.add(line.toLowerCase(locale));
}
} catch (IOException i) {}
}
});
thread.start();
}
示例8: readAssetsJson
import android.content.res.AssetManager; //导入方法依赖的package包/类
/**
* 读取assets下的json数据
*/
private String readAssetsJson() {
AssetManager assetManager = getActivity().getAssets();
try {
InputStream is = assetManager.open("region.json");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
String str;
while ((str = br.readLine()) != null) {
stringBuilder.append(str);
}
return stringBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
示例9: Transliterator
import android.content.res.AssetManager; //导入方法依赖的package包/类
public Transliterator(Context context) {
AssetManager assets = context.getAssets();
InputStream stream = null;
try {
stream = assets.open(TRANSLITERATION_PROPERTIES);
transliteration = new Properties();
transliteration.load(new InputStreamReader(stream, "UTF-8"));
stream.close();
}
catch (IOException e) {
transliteration = null;
}
}
示例10: Level4
import android.content.res.AssetManager; //导入方法依赖的package包/类
public Level4(PlayScreen ps, MainActivity act){
this.ps = ps;
try {
AssetManager assetManager = act.getAssets();
InputStream inputStream = assetManager.open("maps/map4.jpg");
map = BitmapFactory.decodeStream(inputStream);
mapEdge = BitmapFactory.decodeStream(assetManager.open("maps/map4edges.png"));
inputStream.close();
}catch(Exception e){
//dont care sorry
}
}
示例11: Level1
import android.content.res.AssetManager; //导入方法依赖的package包/类
public Level1(PlayScreen ps, MainActivity act){
this.ps = ps;
try {
AssetManager assetManager = act.getAssets();
InputStream inputStream = assetManager.open("maps/map1.jpg");
map = BitmapFactory.decodeStream(inputStream);
inputStream.close();
}catch(Exception e){
//dont care sorry
}
}
示例12: readLabels
import android.content.res.AssetManager; //导入方法依赖的package包/类
public static String[] readLabels(Context context) {
AssetManager assetManager = context.getAssets();
ArrayList<String> result = new ArrayList<>();
try (InputStream is = assetManager.open(LABELS_FILE);
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = br.readLine()) != null) {
result.add(line);
}
return result.toArray(new String[result.size()]);
} catch (IOException ex) {
throw new IllegalStateException("Cannot read labels from " + LABELS_FILE);
}
}
示例13: serveWebIDE
import android.content.res.AssetManager; //导入方法依赖的package包/类
private Response serveWebIDE(IHTTPSession session) {
Response res = null;
String uri = session.getUri();
// Clean up uri
uri = uri.trim().replace(File.separatorChar, '/');
if (uri.indexOf('?') >= 0) uri = uri.substring(0, uri.indexOf('?'));
if (uri.length() == 1) uri = "index.html"; // We never want to request just the '/'
if (uri.charAt(0) == '/') uri = uri.substring(1, uri.length()); // using assets, so we can't have leading '/'
String mime = getMimeType(uri); // Get MIME type
// Read file and return it, otherwise NOT_FOUND is returned
AssetManager am = mContext.get().getAssets();
try {
MLog.d(TAG, WEBAPP_DIR + uri);
InputStream fi = am.open(WEBAPP_DIR + uri);
res = newFixedLengthResponse(Response.Status.OK, mime, fi, fi.available());
} catch (IOException e) {
e.printStackTrace();
MLog.d(TAG, e.getStackTrace().toString());
NanoHTTPD.newFixedLengthResponse( Response.Status.NOT_FOUND, MIME_TYPES.get("txt"), "ERROR: " + e.getMessage());
}
return res; //NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), inp, fontSize);
}
示例14: readAssertResource
import android.content.res.AssetManager; //导入方法依赖的package包/类
public static String readAssertResource(Context context, String strAssertFileName) {
AssetManager assetManager = context.getAssets();
String strResponse = "";
try {
InputStream ims = assetManager.open(strAssertFileName);
strResponse = getStringFromInputStream(ims);
} catch (IOException e) {
e.printStackTrace();
}
return strResponse;
}
示例15: createManifest
import android.content.res.AssetManager; //导入方法依赖的package包/类
private void createManifest(AndroidProjectFolder projectFile, String activityClass, String packageName,
AssetManager assets) throws IOException {
File manifest = projectFile.getXmlManifest();
InputStream manifestTemplate = assets.open("templates/src/main/AndroidManifest.xml");
String contentManifest = FileManager.streamToString(manifestTemplate).toString();
contentManifest = contentManifest.replace("{PACKAGE}", packageName);
contentManifest = contentManifest.replace("{MAIN_ACTIVITY}", activityClass);
Log.d(TAG, "doCreateProject contentManifest = " + contentManifest);
FileManager.saveFile(manifest, contentManifest);
}