我在单击按钮时打开相机并拍照并在imageview中显示它。它正在Google Nexus中运行。但这在Samsung Tab和Micromax canvas HD中不起作用,为什么?

我的按钮点击代码:

       CAMERA_PIC_REQUEST = 100;

     String path =  Environment.getExternalStorageDirectory()
            + "/MySampleApp/image.jpg";

            File file = new File(path);
            Uri outputFileUri = Uri.fromFile(file);

            Intent cameraIntent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);


OnActivityResult代码:

         BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;
              Bitmap bitmap = BitmapFactory.decodeFile(path,
                            options);
                    mImageView.setImageBitmap(bitmap);


manifest.xml中的权限

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />


为什么此代码在三星和micromax中不起作用?

这是正确的代码吗?

有人可以帮我吗?

最佳答案

尝试这个

 btn.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0)
            {
                CAMERA_PIC_REQUEST = 100;
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
            }
        });




@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
     super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
      Bitmap photo = (Bitmap) data.getExtras().get("data");
      mImageView.setImageBitmap(photo);
      }
    }

08-17 05:08