【问题标题】:Using emulator to test taking photos using intent使用模拟器测试使用意图拍照
【发布时间】:2013-06-14 15:17:18
【问题描述】:

我可以使用 Android 模拟器来测试使用 Intent 拍摄照片吗?我问这个是因为,当我在模拟器中使用相机时,它会崩溃(不是通过任何程序,而是从模拟器中获取。)

而且可能会注意到,当我单击模拟器中的“拍照”按钮时(运行我的程序时),我无法拍照。 这里发生了什么?我应该考虑在物理设备而不是模拟器中进行测试吗?或者有什么解决办法?

【问题讨论】:

标签: android emulation


【解决方案1】:

只需使用 Android avd 2.3.3(Level 10) 进行检查

权限

<uses-permission android:name="android.permission.CAMERA"/>

试试这个代码

 protected static final int CAPTURE_PICTURE_INTENT = 2;

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
startActivityForResult(intent, CAPTURE_PICTURE_INTENT);


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_PICTURE_INTENT) {

            try{
                imagePath = destination.getAbsolutePath();
                Bitmap bmp = BitmapFactory.decodeFile(imagePath);
                img_profile.setImageBitmap(bmp);

                //System.out.println(cn.ConvertBase64(bmp));
                base64ImageString = mh.ConvertBase64(bmp);

            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

【讨论】:

  • 修改代码的实际需要是什么,根据文档,模拟器的工作方式与物理设备完全相同。你说什么?
  • 可能是您错过了权限。只需检查一次。如果您授予权限,它将打开相机..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-13
  • 1970-01-01
  • 2021-08-21
  • 2013-08-28
  • 2017-03-07
相关资源
最近更新 更多