我正在尝试使用MediaStore.ACTION_IMAGE_CAPTURE意图捕获照片,但我遇到了一些问题,让它做我想做的事情。我有相机启动,我可以用它拍照,但我需要执行一些不同的操作,具体取决于在什么阶段按下什么按钮。
基本上:
在我的活动中,我有一个方法,我从我的onCreate方法调用:
private void dispatchTakePictureIntent() {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (i.resolveActivity(getPackageManager()) != null) {
startActivityForResult(i, REQUEST_IMAGE_CAPTURE);
}
}
这似乎工作正常。我遇到的问题与我的onActivityResult方法有关。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap image = (Bitmap )extras.get("data");
// Here is where I'm stuck. The docs I've found
// are saying this is only a thumbnail.
// I need to get it as a byte array, I think.
dispatchTakePictureIntent(); // I'm getting camera intents stacking
// on top of each other from this
// I think there's a way to close them
// after launching a new one
}
// Here is where I think I need to put the if statement
// to handle the Discard resultCode
}
// I'm trying to save the photos and upload them to parse
private void savePhoto(byte[] data) {
parseFile = new ParseFile(ParseUser.getCurrentUser().getUsername()
+ System.currentTimeMillis() + .jpg", data);
// Some other parse methods
parseFile.saveInBackground(new SaveCallBack() {
// More parse stuff
});
}
这是我第一次使用相机,所以我一直在阅读Android文档,但我找不到太多帮助。