How to store Image location (fetching from filepicker/Intent) in Sqlite

╄→尐↘猪︶ㄣ 提交于 2019-12-25 08:13:05

问题


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



来源:https://stackoverflow.com/questions/36936165/how-to-store-image-location-fetching-from-filepicker-intent-in-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!