I am extracting the image from my application using the phone camera and using the android.provider.MediaStore.ACTION_IMAGE_CAPTURE file.
After pressing the capture button, save or reset is displayed. By clicking the "Save" button, he returns back to the camera, and not to the application. and the image is saved in the gallery not to the output file that I announced.
Below is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent in=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(in, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode==RESULT_OK) {
Bitmap bm=(Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "player1.jpg");
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}finally{
Intent pic=new Intent(pic1.this, GameMenu.class);
startActivity(pic);
finish();
}
}
else {
Toast.makeText(getApplicationContext(), "Canceled", Toast.LENGTH_LONG).show();
Intent pic=new Intent(pic1.this, Menu.class);
startActivity(pic);
finish();
}
Please suggest if any solution .. Thanks in advance ...
EDIT 1: I checked this code on samsung galaxy y duos (android 2.3.6), which does not work properly. And I checked the same thing on the galaxy pop (2.2.1) and HTC wildfire (2.3.5), that it works fine.