Wie bekomme ich einen InputStream auf eine Resource ?

  • Antworten:1
Mac Systems
  • Forum-Beiträge: 1.727

29.10.2009, 05:49:13 via Website

Wie bekomme ich einen InputStream auf eine RAW resource ?
Ich bekomme die Uri mittels:


public static Uri getResourceURI(final Context _context, final int _resourceId)
{
if (_context == null)
{
throw new NullPointerException("Context is null.");
}

final StringBuilder builder = new StringBuilder(128);
builder.append("android.resource://");
builder.append(_context.getPackageName());
builder.append("/");
builder.append("/");
builder.append(_resourceId);

return Uri.parse(builder.toString());
}

Wie aber damit weiterarbeiten, wenn ich das ganze Zeilenweise einlesen möchte ?

Hier ein grober Ansatz der verdeutlichen soll was ich damit anstellen will :

public final static List<String> getUpdateScript(final Context _context)
{

final Uri uri = IOUtils.getResourceURI(_context, R.raw.updatedatabase);
BufferedReader reader = null;
try
{
// How to get Inputstream ?
reader.readLine();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

29.10.2009, 17:19:59 via Website

Es war mal wieder zu spät:

Resource#openRawResource(int id, TypedValue value) liefert einen InputStream :grin:

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten