Q:

How to handle "_data" field?

I'm trying to store large files (bitmaps) in my Content Provider but don't know how. I've added a "_data" field to my records and have overridden the openFile() method of my Content Provider.
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table contact ( _id integer primary key autoincrement, NAME text collate nocase, IMAGE text, _data text );");
}

public ParcelFileDescriptor openFile(Uri uri, String mode)
    throws FileNotFoundException {

    String rowID = uri.getPathSegments().get(1);
    String dir = Environment.DIRECTORY_PICTURES;

    File file = new File(getContext().getExternalFilesDir(dir), rowID);
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    int fileMode = 0;
    if (mode.contains("w"))
        fileMode |= ParcelFileDescriptor.MODE_WRITE_ONLY;
    if (mode.contains("r"))
        fileMode |= ParcelFileDescriptor.MODE_READ_ONLY;
    if (mode.contains("+"))
        fileMode |= ParcelFileDescriptor.MODE_APPEND;
    return ParcelFileDescriptor.open(file, fileMode);
}

I'm using the Content Resolver's openOutputStream() method to insert bitmaps.
ContentValues values = new ContentValues();
values.put("NAME", "abc");
Uri rowUri = cr.insert(MyContentProvider.CONTENT_URI, values);
values.put("IMAGE", rowUri.toString());
cr.update(rowUri, values, null, null);

InputStream inputStream = httpConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
try {
    Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://www.xyz.com/abc.jpg").getContent());
    bitmap.compress(Bitmap.CompressFormat.JPEG, 80, cr.openOutputStream(rowUri));
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

When I'm doing like this, the file is stored at my SD card, but the "_data" field keeps empty. What I'm doing wrong?
Do I need to write the "_data" field by myself? According this tutorial  the answer seems to be "yes". The "_data" field is written inside the insert() method with the exact file path on the device for that file. The URI reference IMAGE inside the record is not necessary. But the tutorial is already some years old and I haven't found another example where "_data" is directly written like this. Does someone know a good example?

A:

The suggested solution in the mentioned tutorial works.

