Result code 0 for Camera Intent

前端 未结 1 1154
孤独总比滥情好
孤独总比滥情好 2021-01-14 16:34

Code:-

  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);                                   
        try{
               imageUr         


        
相关标签:
1条回答
  • 2021-01-14 17:21

    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 讨论(0)
提交回复
热议问题