本文整理了Java中android.content.res.Resources.openRawResource
方法的一些代码示例,展示了Resources.openRawResource
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.openRawResource
方法的具体详情如下:
包路径:android.content.res.Resources
类名称:Resources
方法名:openRawResource
暂无
代码示例来源:origin: stackoverflow.com
try {
Resources res = getResources();
InputStream in_s = res.openRawResource(R.raw.help);
byte[] b = new byte[in_s.available()];
in_s.read(b);
txtHelp.setText(new String(b));
} catch (Exception e) {
// e.printStackTrace();
txtHelp.setText("Error: can't show help.");
}
代码示例来源:origin: googlemaps/android-maps-utils
/**
* Creates a new KmlLayer object - addLayerToMap() must be called to trigger rendering onto a map.
*
* @param map GoogleMap object
* @param resourceId Raw resource KML file
* @param context Context object
* @throws XmlPullParserException if file cannot be parsed
*/
public KmlLayer(GoogleMap map, int resourceId, Context context)
throws XmlPullParserException, IOException {
this(map, context.getResources().openRawResource(resourceId), context);
}
代码示例来源:origin: ACRA/acra
@Override
public InputStream getInputStream(@NonNull Context context) {
return context.getResources().openRawResource(rawRes);
}
}
代码示例来源:origin: nostra13/Android-Universal-Image-Loader
/**
* Retrieves {@link InputStream} of image by URI (image is located in drawable resources of application).
*
* @param imageUri Image URI
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
* DisplayImageOptions.extraForDownloader(Object)}; can be null
* @return {@link InputStream} of image
*/
protected InputStream getStreamFromDrawable(String imageUri, Object extra) {
String drawableIdString = Scheme.DRAWABLE.crop(imageUri);
int drawableId = Integer.parseInt(drawableIdString);
return context.getResources().openRawResource(drawableId);
}
代码示例来源:origin: bumptech/glide
private byte[] getCanonicalBytes() throws IOException {
int resourceId = ResourceIds.raw.canonical;
Resources resources = context.getResources();
InputStream is = resources.openRawResource(resourceId);
return ByteStreams.toByteArray(is);
}
}
代码示例来源:origin: bumptech/glide
private byte[] loadVideoBytes() throws IOException {
Resources resources = context.getResources();
InputStream is = resources.openRawResource(ResourceIds.raw.video);
return ByteStreams.toByteArray(is);
}
}
代码示例来源:origin: aporter/coursera-android
private void copyImageToMemory(File outFile) {
try {
BufferedOutputStream os = new BufferedOutputStream(
new FileOutputStream(outFile));
BufferedInputStream is = new BufferedInputStream(getResources()
.openRawResource(R.raw.painter));
copy(is, os);
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException");
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
@SuppressLint("ResourceType")
@Override
public InputStream getStream(String imageUri, Object extra) throws IOException {
if (isDownloadingThumbnail()) {
return super.getStream(imageUri, extra);
} else {
return resources.openRawResource(R.drawable.dummy_thumbnail_dark);
}
}
代码示例来源:origin: bumptech/glide
private byte[] getBytes(int resourceId) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
InputStream is = null;
try {
is = context.getResources().openRawResource(resourceId);
byte[] buffer = new byte[1024 * 1024];
int read;
while ((read = is.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignored;
}
}
}
return os.toByteArray();
}
代码示例来源:origin: airbnb/lottie-android
/**
* Parse an animation from raw/res. This is recommended over putting your animation in assets because
* it uses a hard reference to R.
* The resource id will be used as a cache key so future usages won't parse the json again.
*/
@WorkerThread
public static LottieResult<LottieComposition> fromRawResSync(Context context, @RawRes int rawRes) {
try {
return fromJsonInputStreamSync(context.getResources().openRawResource(rawRes), rawResCacheKey(rawRes));
} catch (Resources.NotFoundException e) {
return new LottieResult<>(e);
}
}
代码示例来源:origin: robolectric/robolectric
private static InputStream getImageInputStream() {
return ApplicationProvider.getApplicationContext()
.getResources()
.openRawResource(R.drawable.robolectric);
}
代码示例来源:origin: bumptech/glide
private InputStream getData() {
InputStream is = null;
try {
is = context.getResources().openRawResource(ResourceIds.raw.canonical);
byte[] buffer = new byte[1024 * 1024];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
int read;
while ((read = is.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
byte[] data = outputStream.toByteArray();
return new ByteArrayInputStream(data);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignored.
}
}
}
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options options) {
if (id == 0) {
return null;
}
final TypedValue value = new TypedValue();
InputStream is = res.openRawResource(id, value);
Point imageSizeFromStream = getImageSizeFromStream(is);
Bitmap bitmap = create("resource:" + res.getResourceName(id), options, imageSizeFromStream);
ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
shadowBitmap.createdFromResId = id;
return bitmap;
}
代码示例来源:origin: robolectric/robolectric
@Test @Config(qualifiers = "fr")
public void openRawResource_shouldLoadDrawableWithQualifiers() throws Exception {
InputStream resourceStream = resources.openRawResource(R.drawable.an_image);
Bitmap bitmap = BitmapFactory.decodeStream(resourceStream);
assertThat(bitmap.getHeight()).isEqualTo(100);
assertThat(bitmap.getWidth()).isEqualTo(100);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void openRawResource_shouldLoadDrawables() throws Exception {
InputStream resourceStream = resources.openRawResource(R.drawable.an_image);
Bitmap bitmap = BitmapFactory.decodeStream(resourceStream);
assertThat(bitmap.getHeight()).isEqualTo(53);
assertThat(bitmap.getWidth()).isEqualTo(64);
}
代码示例来源:origin: googlemaps/android-maps-utils
private void readItems() throws JSONException {
InputStream inputStream = getResources().openRawResource(R.raw.radar_search);
List<MyItem> items = new MyItemReader().read(inputStream);
mClusterManager.addItems(items);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void openRawResource_shouldLoadRawResources() throws Exception {
InputStream resourceStream = resources.openRawResource(R.raw.raw_resource);
assertThat(resourceStream).isNotNull();
// assertThat(TestUtil.readString(resourceStream)).isEqualTo("raw txt file contents");
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected InputStream openRawResource(int id) throws Resources.NotFoundException {
if (isLegacyAssetManager()) {
ShadowLegacyAssetManager shadowAssetManager = legacyShadowOf(realResources.getAssets());
ResourceTable resourceTable = shadowAssetManager.getResourceTable();
InputStream inputStream = resourceTable.getRawValue(id, shadowAssetManager.config);
if (inputStream == null) {
throw newNotFoundException(id);
} else {
return inputStream;
}
} else {
return directlyOn(realResources, Resources.class).openRawResource(id);
}
}
代码示例来源:origin: googlemaps/android-maps-utils
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
代码示例来源:origin: googlemaps/android-maps-utils
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
内容来源于网络,如有侵权,请联系作者删除!