1
public class FulfillPhotoTaskActivity extends Activity implements OnClickListener {


ImageView iv;
Uri outputFileUri;
Button takePhoto;
Button uploadPhoto;
Bitmap bmp;
Intent cameraIntent;
File file;
final static int cameraData = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fulfill_photo_task);
    initialize();


}
private void initialize() {
    iv = (ImageView) findViewById(R.id.imageView1);
    takePhoto = (Button) findViewById(R.id.takePhoto);
    takePhoto.setOnClickListener(this);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_fulfill_photo_task, menu);
    return true;
}
@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp");
    String folder = root.toString(); 
    file = new File(folder, "fileName" + ".jpg");
    Uri outputFileUri = Uri.fromFile(file);

    cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

    startActivityForResult(cameraIntent, cameraData);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == RESULT_OK)
    {
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        iv.setImageBitmap(bmp);

    }
}


}

当我在模拟器上运行这个程序时,在拍照并按下检查以使用拍摄的照片后,它什么也没做 - 它不会转到ImageView.

这段代码有错误吗?

4

1 回答 1

0

Android 模拟器充满了数不胜数的错误。这听起来很简单,但你在实际设备上试过吗?我在模拟器上有很多不好的juju,在进入设备后就消失了。

于 2012-11-05T00:00:54.853 回答