Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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摄像头在某些设备上不工作_Android_Android Camera Intent_Onactivityresult - Fatal编程技术网

Android摄像头在某些设备上不工作

Android摄像头在某些设备上不工作,android,android-camera-intent,onactivityresult,Android,Android Camera Intent,Onactivityresult,在我的应用程序中,有一个按钮可以启动相机意图并在给定路径保存捕获的图像。当用户单击相机上的右标记或保存选项时,捕获的图像将被保存。同时,当用户单击相机上的右标记或保存选项时,将调用camera intent launcher活动的onActivityResult()。这一切正常,但在某些设备上,在单击按钮时启动相机,但当用户在拍摄图像后单击“保存”按钮时,相机不会关闭,也不会返回到onActivityResult()。为了启动相机,我使用了这个意图 String path = Environme

在我的应用程序中,有一个按钮可以启动相机意图并在给定路径保存捕获的图像。当用户单击相机上的右标记或保存选项时,捕获的图像将被保存。同时,当用户单击相机上的右标记或保存选项时,将调用camera intent launcher活动的onActivityResult()。这一切正常,但在某些设备上,在单击按钮时启动相机,但当用户在拍摄图像后单击“保存”按钮时,相机不会关闭,也不会返回到
onActivityResult()
。为了启动相机,我使用了这个意图

String path = Environment.getExternalStorageDirectory().toString();
Log.d("PATH", path);
File myNewFolder = new File(path + "/it/Snapshots/");
myNewFolder.mkdirs();
cameraIntent.putExtra( android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path + "/it/Snapshots/"+ic+".jpg")));
startActivityForResult(cameraIntent,1888);
请帮助解决此问题…我感谢您宝贵的回答。请提前感谢使用此代码:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

    try {
        intent.putExtra("return-data", true);
        startActivityForResult(intent, PICK_FROM_CAMERA);
    }
    catch (ActivityNotFoundException e)
    {
        e.printStackTrace();
    }
在onActivityResult中:

if (intent != null && resultcode == RESULT_OK)
             {             

                   Uri selectedImage = intent.getData();

                   String[] filePathColumn = {MediaStore.Images.Media.DATA};
                   Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                   cursor.moveToFirst();
                   int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                   String filePath = cursor.getString(columnIndex);
                   Log.v("log","filePath is : "+filePath);

                   cursor.close();
                   try 
                   {
                        ExifInterface exif = new ExifInterface(filePath);
                         orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                        //Toast.makeText(getApplicationContext(), ""+orientation, 1).show();
                        Log.v("log", "ort is "+orientation);

                   } 
                   catch (IOException e)
                   {
                       e.printStackTrace();
                   }

                   if(bmp != null && !bmp.isRecycled())
                   {
                       bmp = null;               
                   }

                   File f = new File(filePath);

                   if (orientation==6)
                   {
                        Matrix matrix = new Matrix();
                        matrix.postRotate(90);
                        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
                   }
                   else if (orientation==8)
                   {
                        Matrix matrix = new Matrix();
                        matrix.postRotate(270);
                        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
                   }

                   else if (orientation==3)
                   {
                        Matrix matrix = new Matrix();
                        matrix.postRotate(180);
                        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
                   }

                   else if (orientation==0)
                   {
                        Matrix matrix = new Matrix();
                        matrix.postRotate(0);
                        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
                   }



             }
             else
             {
                 Log.v("log", "Photopicker canceled");           
             }

你确定/it/snaphots是可写的(或存在的)?@Rob是的,不确定是否可写,但如果不存在,它将创建由.mkdirs()负责的文件。不管怎样,它在某些设备上工作,你可能没有任何外部存储?@DiscoS2你是对的,谢谢,这就是问题所在。然后如何在手机内部存储器上创建目录感谢您宝贵的回答…我发现外部存储器存在问题…没有外部存储器,所以它无法工作…您能帮助我如何在内部存储器中创建目录吗