简体   繁体   English

银河s5手机中的相机出现问题

[英]Having Problems with Camera in galaxy s5 phone

I'm working on a new app. 我正在开发一个新的应用程序。 The app uses the camera and the external storage. 该应用程序使用相机和外部存储。 While on my LG G3 the app works fine, (as well as on the AVD emulator), when testing it on a Samsung S5, when I get the result from the camera, after taking the photo (in the onActivityResult Method) it seems like there is no result. 在我的LG G3上,该应用程序运行良好(以及在AVD模拟器上),当在Samsung S5上对其进行测试时,当我从相机获得结果时,在拍照后(在onActivityResult方法中)看起来没有结果。 The Intent is null. Intent为null。 I'll just add and say that the photo is being taken, and saved in the specified location, but for some reason i cant use it. 我只是添加并说照片正在拍摄,并保存在指定的位置,但是由于某些原因,我无法使用它。 As said, the same exact code works fine on my G3. 如前所述,相同的确切代码可以在我的G3上正常工作。

I've also tried to create a camera test-app from scratch, again it works only on the G3 and emulator. 我也尝试过从头开始创建一个相机测试应用程序,它再次仅适用于G3和模拟器。

code: 码:

static final int REQUEST_TAKE_PHOTO = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

String mCurrentPhotoPath;    
Bitmap bitmapImg;


private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
        /*Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);*/

        bitmapImg = BitmapFactory.decodeFile(mCurrentPhotoPath);
        mImageView.setImageBitmap(bitmapImg);
    }
}


@Override
public void onClick(View view) {
    dispatchTakePictureIntent();
}

Also as said, the data Intent is null only on the samsung phone. 同样如所述,数据意图仅在三星手机上为空。 Is there anything different on S5 regarding camera, Or permmisions? S5的摄像头或透孔镜有什么不同吗? I'd love to get some help, It is very important to me. 我很想得到一些帮助,这对我来说很重要。 Thanks in advance. 提前致谢。

For me the whole problem was: 对我来说,整个问题是:

 android:launchMode="singleInstance"

In the AndroidManifest. 在AndroidManifest中。 Removing it solved it. 删除它解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM