在Content Provider中访问文件
Content Provider代表的文件是完全符合URI的,而不是raw文件数据。为了插入一个文件到Content Provider或者访问一个保存了的文件,使用ContentResolver的openOutputStream或openInputStream方法。储存文件的过程如下面的代码片段所示:
// Insert a new row into your provider, returning its unique URI.
Uri uri = getContentResolver().insert(MyProvider.CONTENT_URI, newValues);
try {
// Open an output stream using the new row’s URI.
OutputStream outStream = getContentResolver().openOutputStream(uri);
// Compress your bitmap and save it into your provider.
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
}
catch (FileNotFoundException e) { }