Android - downloading image from web, saving to internal memory in location private to app, displaying for list item

后端 未结 3 1369
Happy的楠姐
Happy的楠姐 2021-02-06 11:35

What I\'m trying to do is this: I want my application to download an image from the Internet and save it to the phone\'s internal memory in a location that is private to the app

3条回答
  •  遇见更好的自我
    2021-02-06 12:17

    Looks like simply referring to the image file name when trying to read it was not enough, and I had to call getFilesDir() to get the path of the file storage. Below is the code I used:

    String path = context.getFilesDir().toString();
    String fileName = cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_PRODUCT_ID));
    
    if (fileName != null && !fileName.equals("")) {
        Bitmap bMap = BitmapFactory.decodeFile(path + "/" + fileName);
        if (bMap != null) {
            thumbnail.setImageBitmap(bMap);
        }
    }
    

提交回复
热议问题