相机意图的结果代码0 [英] Result code 0 for Camera Intent

查看:85
本文介绍了相机意图的结果代码0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:-

  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);                                   
        try{
               imageUri = Uri.fromFile(File.createTempFile("image", ".jpg"));
           }catch (Exception ex){
               ex.printStackTrace();
          }

   intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intent, REQUEST_CAMERA);

我正在android清单文件中使用与此相关的所有权限... 上面的意图在mot g3 turbo和更多设备中都可以正常工作,但是在仅nexus 5的情况下,resultCode即将变为0 ..为什么呢?

I am using all permissions related to this in android manifest file... that above intent is working fine in mot g3 turbo and many more devices but in the case of only nexus 5 the resultCode is coming 0.. why?

推荐答案

在CommonsWare先生的指导下,我通过以下更改解决了我的问题...

With the guidance of CommonsWare Sir, I resolved my problem by doing the following changes...

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
destination = Environment.getExternalStorageDirectory().getPath() + "/image.jpg";
outputUri= Uri.fromFile(new File(destination));
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) {
  intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
} else {
  List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
  for (ResolveInfo resolveInfo : resInfoList) {
      String packageName = resolveInfo.activityInfo.packageName;
      grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
  }
}         

startActivityForResult(intent, REQUEST_CAMERA); 

这篇关于相机意图的结果代码0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆