将图像保存到我的图库中

时间:2016-03-21 16:18:32

标签: java android android-studio

我正在Android工作室制作Android应用程序,用户可以在其中将照片保存到其库中的新文件夹中。目前,该应用程序拍摄的照片很好,但不会将图像保存到我的图库中的新“SOC”文件夹中。我没有收到任何错误,我不知道为什么它没有保存图像。任何帮助将不胜感激。

我的代码是休闲

static final int REQUEST_IMAGE_CAPTURE = 1;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
public void onClickbtnCamera(View v)
{
    Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    Uri uriSavedImage=Uri.fromFile(new File("/storage/emulated/0/DCIM/SOC","QR_"+timeStamp+ ".png"));
    imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    startActivityForResult(imageIntent, 1);
}



   @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {

            //Check for succesful result code
            if (resultCode == -1) {
                //Show your Toast when the result is a success.
                Toast toast = Toast.makeText(getApplicationContext(),
                        "Picture is saved in your SOC gallery", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 100, 0);
                toast.show();
            }
        }
    }

2 个答案:

答案 0 :(得分:0)

我认为您必须手动将新照片Uri添加到媒体内容提供商。 看看here

答案 1 :(得分:0)

在您的活动结果中调用此方法

    $mylink = $wpdb->get_results($query);
    if (count($mylink) > 0){
        foreach ($mylink as $prj){
            $galleries = Array();
            $pid = $prj->id;
            $gs = get_field('gallery', $pid);
            if($gs == null){
                $gs = Array();
            }

            foreach ($gs as $g){
                $c = new stdclass();
                $c -> id = $g["ID"];
                $c -> url = $g["url"];
                $galleries [] = $c;
            }
            $prj -> PID = $pid;
            $prj -> GS = $gs;
            $prj -> gallery  = $galleries;
            $prj -> image = ''.wp_get_attachment_url( get_post_thumbnail_id($prj->id) );
        }
        $results_array['msg'] = 'Success';
        $results_array['status'] = true;
        $results_array['result'] = $mylink;
        $results_array['current_time'] = date("Y-m-d H:i:s");
        return $results_array;
    }

你应该在启动意图之前保存照片路径,然后getCurrentPhotoPath()必须获得该路径