我从我的应用程序使用手机的相机捕获图像,并使用android.provider.MediaStore.ACTION_IMAGE_CAPTURE。使用手机摄像头,捕获图像活动后不返回到特定活动
点击捕捉按钮后,显示保存或放弃。点击保存按钮,它会返回到相机而不是应用程序。并且图像保存在gallary而不是我已经声明的输出文件中。
下面是我的代码
如果任何解决方案.. 在此先感谢...编辑1
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
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) {
// TODO Auto-generated method stub
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);
//you can create a new file name "test.jpg" in sdcard folder.
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "player1.jpg");
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//write the bytes in file
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fo.write(bytes.toByteArray());
} catch (IOException e) {
// TODO Auto-generated catch block
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();
}
请提示:我已经检查了三星GalaxyŸ二重奏代码(Android 2.3的。 6)它不能正常工作。并检查相同的星系流行(2.2.1)和HTC野火(2.3.5)其工作完美。
您是否尝试检查onActivity结果中的响应代码? –