How to store Image location (fetching from filepic

2019-09-04 07:10发布

问题:

I am new to Android Development. I am trying to store Image file location in Sqlite database. Image is received from Intent with any file manager or gallery. I want to store its real path into the database so i can retrieve it next time for any action. I don't want to use blob/dont want to store image in the database. I am not finding any better solutions. Please help.

回答1:

You can store an image in database as bytearray or also store image URL as TEXT in sqlite dataBase



回答2:

Try this

 Intent name=new Intent(Intent.ACTION_GET_CONTENT);

 name.setType("image/*.png");   // It could be any files extension that your going to search

startActivityForResult(name, requestCode);

And also Override onActivityResult() method

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{

String path=data.getData().getPath();
//Here insert the path into database
}


回答3:

You can save the image path and always check if the path is valid or exists.

You can use an intent to pick up the image:

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, PICK_IMAGE_REQUEST_CODE);

And get the image path:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PICK_IMAGE_REQUEST_CODE) {
        /** You have to call the getData or getDataString to get the images address */
        Log.i("CCC", data.getDataString());
    }
}

With the path you can save it in the database.

Enjoy it!!