我正在制作一个 android 应用程序,它从相机中获取图像然后显示它。但是,我无法显示单击的图像可能是因为onActivityResult()
未触发。
这是我的一段代码。谁能建议我我错过了什么?
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final int CAMERA_PIC_REQUEST = 1337;
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
@override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("Message1", "I reached 2");
//super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_PIC_REQUEST) {
// do something
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(thumbnail);
}
}
});
}
}