I wanted to take a photo and save it to gallery. Then read this photo from gallery and convert it to text( using ocr)
But my app keep crashing when I try to save it with this line of code
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
I debug my app and found this line is the responsible for crash. But without this line I can't save my image. How can I do that ?
package com.example.takepicture;
import ...
public class MainActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCamera = (Button) findViewById(R.id.btnCamera);
imageView = (ImageView) findViewById(R.id.ImageView);
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String pictureName = getPictureName();
File imageFile = new File(pictureDirectory,pictureName);
Uri pictureUri = Uri.fromFile(imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
//capturarFoto();
}
});
}
private String getPictureName() {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return "Img" + timeStamp + ".jpg";
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_OK) {
if (requestCode == CAMERA_REQUEST) {
}
}
}
}