我在我的应用上使用相机,我有两个问题:
1.拍摄照片后单击保存按钮时,应用程序有时会崩溃
我无法打电话给意图。我在布局上设置了一个按钮(我删除了它),当你点击它时,它应该转到另一个活动,它总是崩溃。
这是我的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0)
{
if (resultCode==RESULT_OK)
{
bmp=(Bitmap)data.getExtras().get("data");
iv.setImageBitmap(bmp);
user.put("picureBMP", BitMapToString(bmp));
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException arg0) {
Intent intent=new Intent(CameraActivity.this,TeacherHomePageActivity.class);
startActivity(intent);
}
});
}
}
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.imgTakePic:
Intent TakePic=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(TakePic,0);
break;
default:
break;
}
}
答案 0 :(得分:0)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0)
{
if (resultCode==RESULT_OK)
{
bmp=(Bitmap)data.getExtras().get("data");
iv.setImageBitmap(bmp);
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
// Create the ParseFile
user.put("picureBMP",file);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException arg0) {
Intent intent=new Intent(CameraActivity.this,TeacherHomePageActivity.class);
startActivity(intent);
}
});
}
}
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.imgTakePic:
Intent TakePic=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(TakePic,0);
break;
default:
break;
}
}