如何将图像保存到图库Android ap

时间:2015-10-26 19:09:13

标签: java android eclipse button

我正在制作一个Android应用程序,当点击一个按钮时它会打开相机然而在拍摄照片后图像无法保存。我希望能够将其保存到我的画廊专辑中。

public void onClickbtnCamera(View v){

    Intent intent1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri uriSavedImage=Uri.fromFile(new File("/storage/emulated/0/DCIM/Camera/"));
    intent1.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    startActivityForResult(intent1,3);

}

1 个答案:

答案 0 :(得分:0)

您正在传递EXTRA_OUTPUT中的目录。 package com.commonsware.android.camcon; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import java.io.File; public class CameraContentDemoActivity extends Activity { private static final int CONTENT_REQUEST=1337; private File output=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File dir= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); output=new File(dir, "CameraContentDemo.jpeg"); i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output)); startActivityForResult(i, CONTENT_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CONTENT_REQUEST) { if (resultCode == RESULT_OK) { Intent i=new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(output), "image/jpeg"); startActivity(i); finish(); } } } } 需要指向一个文件:

this

(来自this sample project