Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 操作\u图像\u捕获导致无法传递结果信息_Android_Android Activity_Camera - Fatal编程技术网

Android 操作\u图像\u捕获导致无法传递结果信息

Android 操作\u图像\u捕获导致无法传递结果信息,android,android-activity,camera,Android,Android Activity,Camera,在SAMSUNG TAB 3中拍摄图像时,在ActivityResult()上给出错误(用于Nexus工作): 是否有任何通用代码可用于所有设备 public void openImageIntent(View view) { // Determine Uri of camera image to save. final File root = new File(KOOPSv3.getFolderPath(context, context.getReso

在SAMSUNG TAB 3中拍摄图像时,在ActivityResult()上给出错误
(用于Nexus工作):

是否有任何通用代码可用于所有设备

    public void openImageIntent(View view) {

        // Determine Uri of camera image to save.
        final File root = new File(KOOPSv3.getFolderPath(context, context.getResources().getString(R.string.folder_expense)));

        final String fname = staff_id + new Date().getTime() + Math.abs(new Random().nextInt()) + ".jpg";

        path = root.getPath() + File.separator + fname;

        Log.d("koopsv3", "PATH : " + path);

        final File sdImageMainDirectory = new File(root, fname);
        outputFileUri = Uri.fromFile(sdImageMainDirectory);

        // Camera.
        final List<Intent> cameraIntents = new ArrayList<Intent>();
        final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        final PackageManager packageManager = 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);
        }

        // File System.
        final Intent galleryIntent = new Intent();
        galleryIntent.setType("image/*");
        galleryIntent.setAction(Intent.ACTION_PICK);

        // Chooser of file system options.
        final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Image");

        // Add the camera options.
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

        startActivityForResult(chooserIntent, 1010);
    }
在Tablet 3的
onActivityResult()
中,我得到了
NULL
,我如何解决这个问题

我怎样才能解决这个问题

如果
Intent
null
,请检查文件是否位于您请求的位置。如果你这样做了,就用它。如果没有,请告诉用户他们选择的应用程序已损坏,然后重试

传递给您的
onActivityResult()
方法的
Intent
是您从另一个应用程序接收的输入。您需要使用防御性编程方法,因为输入可能并不总是您所期望的。理论上,
ACTION\u IMAGE\u CAPTURE
将返回一致的结果。实际上,在数千个摄像头应用程序中有数千种不同的实现,并且不是每个开发人员都能充分测试他们的应用程序
ACTION\u IMAGE\u捕获
处理

    public void openImageIntent(View view) {

        // Determine Uri of camera image to save.
        final File root = new File(KOOPSv3.getFolderPath(context, context.getResources().getString(R.string.folder_expense)));

        final String fname = staff_id + new Date().getTime() + Math.abs(new Random().nextInt()) + ".jpg";

        path = root.getPath() + File.separator + fname;

        Log.d("koopsv3", "PATH : " + path);

        final File sdImageMainDirectory = new File(root, fname);
        outputFileUri = Uri.fromFile(sdImageMainDirectory);

        // Camera.
        final List<Intent> cameraIntents = new ArrayList<Intent>();
        final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        final PackageManager packageManager = 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);
        }

        // File System.
        final Intent galleryIntent = new Intent();
        galleryIntent.setType("image/*");
        galleryIntent.setAction(Intent.ACTION_PICK);

        // Chooser of file system options.
        final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Image");

        // Add the camera options.
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

        startActivityForResult(chooserIntent, 1010);
    }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if(resultCode == RESULT_OK)
    {
        if(requestCode == 1010)
        {
            final boolean isCamera;
            if(data == null)
            {
                isCamera = true;
            }
            else
            {
                final String action = data.getAction();
                if(action == null)
                {
                    isCamera = false;
                }
                else
                {
                    isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                }
            }

            Uri selectedImageUri;
            if(isCamera) {
                selectedImageUri = outputFileUri;

                Log.i("koopsv3", "OutputURI : "+path);
            } else {
                selectedImageUri = data == null ? null : data.getData();
                path = com.ipaulpro.afilechooser.utils.FileUtils.getPath(context, selectedImageUri);
            }
        }
    }
}