How do I save my imageView image into Gallery (Android Development)

前端 未结 5 2077
逝去的感伤
逝去的感伤 2021-01-05 17:01

I am trying to create an onClick event to save an imageview into the phone Gallery by the click of a Button, below is my code. it does not save into the Gallery, can anyone

5条回答
  •  旧时难觅i
    2021-01-05 17:37

    public static void addImageToGallery(final String filePath, final Context context) {
    
        ContentValues values = new ContentValues();
    
        values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(MediaStore.MediaColumns.DATA, filePath);
    
        context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
    }
    

提交回复
热议问题