Android Can I append a specific record field in a URI?
I'm doing Android development.
My question is: can I append a specific field of a db record to a URI?
Example: suppose you have a table monuments in a SQLite DB:
_id INTEGER AUTO INCREMENT
name TEXT
location TEXT
picture BLOB
I want now to retrieve the BLOB image of entry with ID 4 and display it; I can query the db
Bitmap monumentImage = null;
Uri uri = Uri.parse("content://com.my.example/monuments/4");
Cursor c = myContentResolver.query(uri, new String[] {"picture"}, null, null, null);
if (c.moveToFirst()) {
byte[] imageBytes = c.getBlob(0);
if (imageBytes != null) {
monumentImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
}
ImageView myImage = findViewById(R.id.whatever开发者_StackOverflow中文版);
if (monumentImage != null) {
myImage.setImageBitmap(monumentImage);
}
now my question is: is there a way to append directly the record column to the uri? as in, having something like
Uri uri = Uri.parse("content://com.my.example/monuments/4/picture");
ImageView myImage = findViewById(R.id.whatever);
myImage.setImageURI(uri);
?
Cheers!
Yep. Just use own content provider. There you will be able to parse the URI. Read here, the
Making the Query
section.
精彩评论