Samsung Intent For OnActivityResult coming Null when call camera

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

I am using following code to get picture from camera. Except samsung it is working fine in other mobiles. please let me know what i am doing wrong.

 final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "temp" + File.separator);         root.mkdir();         final String fname = "img_" + System.currentTimeMillis() + ".jpg";         final File sdImageMainDirectory = new File(root, fname);         outputFileUri = Uri.fromFile(sdImageMainDirectory);          // Camera.         final List<Intent> cameraIntents = new ArrayList<Intent>();         final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);         final PackageManager packageManager = cordova.getActivity().getPackageManager();         final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);         for (ResolveInfo res : listCam){             final String packageName = res.activityInfo.packageName;             final Intent intent = new Intent(captureIntent);             intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));             intent.setPackage(packageName);             intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);             cameraIntents.add(intent);         }          //FileSystem         final Intent galleryIntent = new Intent();         galleryIntent.setType("image/jpeg");         galleryIntent.setAction(Intent.ACTION_GET_CONTENT);          // Chooser of filesystem options.         final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Image Source");         // Add the camera options.         chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));         startActivityForResult(chooserIntent, PICK_FILE_REQUEST); 

And onActivityResult

 @Override     protected void onActivityResult(int requestCode, int resultCode, Intent data) {          if (requestCode == PICK_FILE_REQUEST) {              if(data!=null){                 Logv("Data","got some data");               }            }     } 

回答1:

Except samsung it is working fine in other mobiles

No, it is only working with the camera apps on the devices that you have tried. It generally will not work for ACTION_IMAGE_CAPTURE.

please let me know what i am doing wrong

You are assuming that ACTION_IMAGE_CAPTURE is supposed to return a result Intent. It is not required when you provide EXTRA_OUTPUT. You know where you asked for the image to be saved (the value you supplied to EXTRA_OUTPUT, so go look there for the image.

Note that there are some buggy camera apps that will ignore EXTRA_OUTPUT (storing the image where they want), so if the image from your ACTION_IMAGE_CAPTURE request is not in EXTRA_OUTPUT, you are out of luck.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!