How to store Image location (fetching from filepic

2019-09-04 06:54发布

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.

3条回答
放荡不羁爱自由
2楼-- · 2019-09-04 07:24

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

查看更多
相关推荐>>
3楼-- · 2019-09-04 07:30

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!!

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-09-04 07:42

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
}
查看更多
登录 后发表回答