Android开发 调用系统相机出现的问题
2014-12-11 17:05
441 查看
现在的项目用到了Android 手机的相机和相册 ,调用系统相册没问题
if (FileUtil.isExistSDCard()) {
Intent intent;
if (ViewUtil.getSDKVerSion() >= 19) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT, null);
} else {
intent = new Intent(Intent.ACTION_GET_CONTENT, null);
}
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, Constants.IMAGE_CONSTANTS);
} else {
ViewUtil.toast(this, R.string.do_not_support);
}
可是调用系统相机的时候出现问题了,手机适配的问题
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getCameraUri());
startActivityForResult(intent, Constants.CAMERE_CONSTANTS);
我的sony 手机能够从 @Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
super.onActivityResult(arg0, arg1, arg2);
}
arg2 中获取数据 ,也就是不为空,但公司还有个google 原生的手机 和一个numa手机 获取数据时出现
android camera : Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity
网上找了一段时间 ,都是推荐去掉这个
intent.putExtra(MediaStore.EXTRA_OUTPUT, getCameraUri()); 不设置图片的的返回的Uri,结果是可以获取到数据
通过//Bitmap bitmap = (Bitmap) arg2.getExtras().get("data"); 可是 ,这里有个问题就是 获取到的图片被压缩了 ,变的很小 ,Android 源码好像说是为了防止oom,
所以还是用上面的方法 不过 获取图片的时候不是用arg2
而是通过这种方法
@Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
super.onActivityResult(arg0, arg1, arg2);
// 相机
if (Constants.CAMERE_CONSTANTS == arg0) {
try {
File file = new File(imagePath);
Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(
getContentResolver(), file.getAbsolutePath(), null,
null));
setIntent(uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
获取到图片的uri
if (FileUtil.isExistSDCard()) {
Intent intent;
if (ViewUtil.getSDKVerSion() >= 19) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT, null);
} else {
intent = new Intent(Intent.ACTION_GET_CONTENT, null);
}
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, Constants.IMAGE_CONSTANTS);
} else {
ViewUtil.toast(this, R.string.do_not_support);
}
可是调用系统相机的时候出现问题了,手机适配的问题
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getCameraUri());
startActivityForResult(intent, Constants.CAMERE_CONSTANTS);
我的sony 手机能够从 @Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
super.onActivityResult(arg0, arg1, arg2);
}
arg2 中获取数据 ,也就是不为空,但公司还有个google 原生的手机 和一个numa手机 获取数据时出现
android camera : Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity
网上找了一段时间 ,都是推荐去掉这个
intent.putExtra(MediaStore.EXTRA_OUTPUT, getCameraUri()); 不设置图片的的返回的Uri,结果是可以获取到数据
通过//Bitmap bitmap = (Bitmap) arg2.getExtras().get("data"); 可是 ,这里有个问题就是 获取到的图片被压缩了 ,变的很小 ,Android 源码好像说是为了防止oom,
所以还是用上面的方法 不过 获取图片的时候不是用arg2
而是通过这种方法
@Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
super.onActivityResult(arg0, arg1, arg2);
// 相机
if (Constants.CAMERE_CONSTANTS == arg0) {
try {
File file = new File(imagePath);
Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(
getContentResolver(), file.getAbsolutePath(), null,
null));
setIntent(uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
获取到图片的uri
相关文章推荐
- Android基础--调用系统相机,打开相册,展示到界面,出现的一些问题Uri为空,data为null,图片错乱问题
- Android开发 调用系统相机相册图片功能,解决小米手机拍照或者图片横竖相反问题,及小米手机相册图片路径问题
- Android开发中调用系统相册上传图片到服务器OPPO等部分手机上出现短暂的显示桌面问题的解决方法
- 调用Android系统相机出现问题
- 解决Android调用系统相机拍照后相片无法在相册中显示问题
- Android开发教程--关于系统相机拍照获取的照片尺寸较小问题的解决
- Android 调用系统相机处理大图片问题
- Android 关于调用系统内已安装的相机问题
- Android开发之调用系统图库及相机
- 解决android调用系统相机拍照保存时onActivityResult中data为null的问题
- Android开发基础 调用相机 系统相册(并对图片进行压缩处理)
- 整理android调用系统相机的方法及遇到的问题
- 整理android调用系统相机的方法及遇到的问题
- Android调用系统相机获取图片尺寸很小问题
- 开发中碰到的问题:小米note调用系统相机点击确定是取消
- android 调用系统相机方法,解决CPU兼容问题
- [Android初级]调用基于WCF开发的WebService出现的问题
- Android开发之调用系统图库及相机
- android调用系统相机,获取照片的适配性问题
- Android开发片段–调用系统相机拍照