当前位置: 首页>>代码示例>>Java>>正文


Java AssetManager.open方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:theopenbit,项目名称:yaacc-code,代码行数:27,代码来源:ActivityTest.java

示例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;
    }
}
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:27,代码来源:HomeRegionFragment.java

示例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) {
    }
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:18,代码来源:AssetUpdater.java

示例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();
}
 
开发者ID:Visions-Team,项目名称:eBread,代码行数:27,代码来源:SettingTTSFragment.java

示例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
        }

    }
 
开发者ID:TheNamesDyl,项目名称:blastar,代码行数:17,代码来源:Level2.java

示例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;
}
 
开发者ID:VK2012,项目名称:AppCommonFrame,代码行数:25,代码来源:BitmapUtil.java

示例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();
}
 
开发者ID:zzzmobile,项目名称:VideoDownloader-Android,代码行数:17,代码来源:AdBlock.java

示例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;
  }
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:21,代码来源:HomeRegionFragment.java

示例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;
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:14,代码来源:Transliterator.java

示例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
        }
    }
 
开发者ID:TheNamesDyl,项目名称:blastar,代码行数:16,代码来源:Level4.java

示例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
        }
    }
 
开发者ID:TheNamesDyl,项目名称:blastar,代码行数:14,代码来源:Level1.java

示例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);
    }
}
 
开发者ID:googlecodelabs,项目名称:androidthings-imageclassifier,代码行数:15,代码来源:Helper.java

示例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);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:28,代码来源:PhonkHttpServer.java

示例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;
}
 
开发者ID:auv1107,项目名称:TextEmoji,代码行数:12,代码来源:AssetUtils.java

示例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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:11,代码来源:DialogNewAndroidProject.java


注:本文中的android.content.res.AssetManager.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。