0
我正在尝试遵循本教程,但问题在于,当我单击应该确认图像的复选标记时,它根本没有做任何事情。我觉得我错过了某种权限来访问SD卡或其他东西。我正在调试模式下测试nexus 7。所有帮助表示感谢。在android中使用相机意图保存位图
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private static ImageView imageView;
protected String _path;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView)this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
_path = Environment.getExternalStorageDirectory() + "/images/camocr";
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = new File(_path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
//Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == -1) {
// Bitmap photo = (Bitmap) data.getExtras().get("data");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(_path, options);
imageView.setImageBitmap(bitmap);
}
}
protected static void identifyunicode() {
// DATA_PATH = Path to the storage
// lang for which the language data exists, usually "eng"
}
}
您将请求代码设置为0,并在onActivityResult中检查-1 – JRowan 2013-04-26 00:31:24