0
亲爱的世界的android开发人员。请帮助我的Android相机问题
请帮助我解决Android相机API问题。
我想通过android相机拍照并将其设置为ImageButton的图像。 如果有媒体商店,则将图像保存到特殊路径。
问题如下。
它适用于某些Android设备,如中兴通讯2.2,三星Galaxy 2.3.3和三星平板4.0.3等
但它不会在其他一些设备如2.3.4 LG Droid上使用。
我的意思是拍摄的图像没有设置为图像按钮。
(2.3.4 LG Droid的设备的详细信息是: 硬件版本:版本.1.1, 软件版本:ms910zbc, 内部版本号姜饼)
这是我的代码。
String mPhotoPath;
ImageButton mPhotoButton;
mPhotoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
File photoFile = new File(mPhotoPath);
try {
if (!photoFile.exists()) {
photoFile.getParentFile().mkdirs();
photoFile.createNewFile();
photoFile.setWritable(true, false);
}
} catch (IOException e) {
}
Uri fileUri = Uri.fromFile(photoFile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, TAKE_PICTURE);
}else {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
}
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
switch (requestCode) {
case TAKE_PICTURE: {
if (data != null) { //ZTE 2.2 device
try {
Bundle extras = data.getExtras();
if (extras != null)
{
fPhoto = extras.getParcelable("data");
mPhotoButton.setImageBitmap(fPhoto);
}
} catch (Exception e) {
e.printStackTrace();
}
}
else //Samsung 2.3.3 device
{
try {
FileInputStream stream = new FileInputStream(new File(mPhotoPath));
fPhoto = BitmapFactory.decodeStream(stream);
stream.close();
mPhotoButton.setImageBitmap(fPhoto);
}catch (Exception e) {
e.printStackTrace();
}
}
break;
}
}
}
我感谢你的帮助。
谢谢。
真诚。
如果它给你的解决方案,接受这个作为答案 – Ponmalar 2012-07-16 03:50:17