一些手机(约20%)上使用Android相机意图会导致应用程序崩溃。

9

我已经对这个问题进行了大量的研究,并看到了一些很好的回复,并找到了一些“解决方案”的好资源。但遗憾的是,在某些设备上,我仍然遇到了很多应用程序崩溃的情况。在某人拍摄照片后,相机意图应该将信息传递回调用活动,但是崩溃发生了。为了我的应用程序的目的,我只是用新拍摄的照片覆盖任何现有的照片,因此我可以几乎使用静态路径来访问文件位置。以下是我调用意图的方式:

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // get the file path from an external class (necessary for galaxy nexus)
        imageFileAndPath = ImageServices.getOutputImageFileUri(cont);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileAndPath);
        startActivityForResult(intent, CAMERA_REQUEST_CODE);

imageFileAndPath只是一个URI变量,我从另一个类中创建它,因为这解决了在几种设备类型上按“完成”或选中特定设备上的检查标记或其他东西来关闭相机意图时没有任何反应的问题。通过从单独的类创建URI,它以某种未知的方式解决了这个问题。

我的onActivityResult代码如下:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == Activity.RESULT_OK)
    {
        if (requestCode == CAMERA_REQUEST_CODE) {
            setupImageView();
    imageView = (ImageView) findViewById(R.id.image_view);
            webView.setVisibility(View.GONE);
            imageView.setVisibility(View.VISIBLE);
            button.setVisibility(View.GONE);
            reTakePicButton.setVisibility(View.VISIBLE);
            rl.setVisibility(View.VISIBLE);    
        }
    }
}

由于我不需要动态路径来保存我的照片(因为它会覆盖现有的照片),所以我只需要在我的活动中调用另一个方法,对照片进行调整大小和旋转。该方法如下:

private void setupImageView() {     
    imageLocation = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myappphoto/myappphoto.jpg";


    // Get the dimensions of the View
    Display display = getWindowManager().getDefaultDisplay();
    Point size = getDisplaySize(display);
    int targetW = size.x;

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;

    BitmapFactory.decodeFile(imageLocation, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetW);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(imageLocation, bmOptions);
    int rotationForImage = getRotationForImage(imageLocation);
    if (rotationForImage != 0) {
        int targetWidth = rotationForImage == 90 || rotationForImage == 270 ? bitmap.getHeight() : bitmap.getWidth();
        int targetHeight = rotationForImage == 90 || rotationForImage == 270 ? bitmap.getWidth() : bitmap.getHeight();




        Bitmap rotatedBitmap = Bitmap.createBitmap(targetWidth, targetHeight, bitmap.getConfig());
        Canvas canvas = new Canvas(rotatedBitmap);
        Matrix matrix = new Matrix();
        matrix.setRotate(rotationForImage, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
        canvas.drawBitmap(bitmap, matrix, new Paint());

        bitmap.recycle();
        bitmap = rotatedBitmap;

    }



    Bitmap resized;

    if(bitmap.getWidth() >= 900 || bitmap.getHeight() >=900)
    {
        int newWidth = Math.round(bitmap.getWidth()/2);
        int newHeight = Math.round(bitmap.getHeight()/2);
        resized = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);
    }
    else
    {
        resized = bitmap;
    }
    //bitmap.recycle();
    bitmap = resized;


    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 70, bytes);

    try
    {
        File f = new File(imageLocation);
        f.createNewFile();
        //write the bytes in file
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
        fo.close();
    }
    catch(java.io.IOException e){}
    imageView.setImageBitmap(bitmap);

}

在该方法的顶部,您可以看到指向从相机意图保存的图像文件的静态路径。

我想可能是调整大小,旋转方法导致崩溃,但我不明白为什么会这样,那看起来对我来说都是很标准的java编码。

有人能看到我在这里做错了什么吗?正如我在这个主题的标题中所说的那样,我的代码在大约20%运行它的设备上会导致崩溃,这是不可接受的。我可以应付5%,但不能应付20%。

我意识到在这方面进行Android开发有点儿恶心,因为您必须考虑到许多不同的设备类型(制造商,Android版本等),但是我认为相机活动应该比这更加标准化。就像我在本主题的开头所说的那样,我已经对此问题进行了很多研究,并且看到了几个与我的问题类似的人们,但没有一种好的解决方案可以涵盖大多数设备。我真的不想从零开始编写自己的相机(也不认为我应该从零开始编写),必须有更好的默认内置相机意图在Android设备上实现...我只是还没有找到它。正如您所见,我甚至不关心动态创建图像,这应该使这个项目更加容易。

谢谢您的帮助

编辑:根据下面的评论,我添加了一个失败相机的堆栈跟踪。看起来像一个空指针异常。我拍了六张照片,并一直使用调用相机意图的按钮返回,直到最终它崩溃了。以下是堆栈跟踪:

STACK_TRACE
"java.lang.RuntimeException: Unable to resume activity {com.myapp/com.myapp.MyActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=904, result=-1, data=null} to activity {com.myapp/com.myapp.MyActivity}: java.lang.NullPointerException
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836)
    at android.app.ActivityThread.access$1600(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=904, result=-1, data=null} to activity {com.myapp/com.myapp.MyActivity}: java.lang.NullPointerException
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2111)
    ... 13 more
Caused by: java.lang.NullPointerException
    at com.myapp.MyActivity.onActivityResult(EnterContest.java:257)
    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
    ... 14 more
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=904, result=-1, data=null} to activity {com.myapp/com.myapp.MyActivity}: java.lang.NullPointerException
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2111)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836)
    at android.app.ActivityThread.access$1600(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at com.myapp.MyActivity.onActivityResult(EnterContest.java:257)
    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
    ... 14 more
java.lang.NullPointerException
    at com.myapp.MyActivity.onActivityResult(EnterContest.java:257)
    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2111)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836)
    at android.app.ActivityThread.access$1600(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)

请发布相关的堆栈跟踪,展示您的“崩溃”性质。 - CommonsWare
@CommonsWare 很不幸,我没有它们可以发布。这些崩溃发生在我无法测试的设备上。该应用程序目前处于测试阶段,一些用户正在经历崩溃,而大多数用户则没有。我该如何设置日志记录以从已经“在现场”的崩溃设备中获取堆栈跟踪信息? - Christopher Johnson
如何设置日志记录以从已经“在现场”的崩溃设备中获取堆栈跟踪信息 - 使用ACRA或类似的库:http://acra.ch。 - CommonsWare
@CommonsWare 好的,我在我的原始帖子中发布了一个堆栈跟踪。为什么它会工作几次,然后出现NPE? - Christopher Johnson
您的堆栈跟踪与源代码不匹配。在此处,onActivityResult() 中没有直接引发 NullPointerException 的行。您正在运行其他实现的 onActivityResult(),我们无法知道它可能包含什么,更不用说为什么会崩溃了。 - CommonsWare
@CommonsWare 您说得对,我省略了一些onActivityResult()的内容,因为我认为它不是罪魁祸首。它主要只是在xml布局上显示/隐藏元素。这些元素在我的活动(类)顶部声明为字段。这些字段值在相机意图期间可能会丢失吗?因此当它返回到调用活动时,它们现在为空吗?非常感谢您在此事上花费的时间。我已经更新了我的OP,其中包含了onActivityResult()方法中的其余内容。 - Christopher Johnson
3个回答

2

也许只是猜测,但我认为我遇到了同样的问题,我通过在新的AsyncTask中读取位图而不是在UI线程中修复了它。

异常发生时(表面上是随机的)调用

getContentResolver().notifyChange(selectedImage, null);

其中selectedImage是之前设置的URI

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

你在com.myapp.MyActivity.onActivityResult(EnterContest.java:257)中调用了什么?

我有一个使用ACRA收集的堆栈跟踪:

java.lang.RuntimeException: Unable to resume activity {com.infonair.meetme.app/com.infonair.meetme.activity.photo.TakePhotoActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=7898789, result=-1, data=Intent { dat=content://media/external/images/media/9 }} to activity {com.infonair.meetme.app/com.infonair.meetme.activity.photo.TakePhotoActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2126)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2141)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2838)
at android.app.ActivityThread.access$1600(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3737)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:894)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=7898789, result=-1, data=Intent { dat=content://media/external/images/media/9 }} to activity {com.infonair.meetme.app/com.infonair.meetme.activity.photo.TakePhotoActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:2538)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2113)
... 13 more
Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1328)
at android.os.Parcel.readException(Parcel.java:1276)
at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:458)
at android.content.ContentResolver.notifyChange(ContentResolver.java:912)
at android.content.ContentResolver.notifyChange(ContentResolver.java:898)
at com.infonair.meetme.activity.photo.TakePhotoActivity.onActivityResult(TakePhotoActivity.java:154)
at android.app.Activity.dispatchActivityResult(Activity.java:3908)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2534)
... 14 more
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=7898789, result=-1, data=Intent { dat=content://media/external/images/media/9 }} to activity {com.infonair.meetme.app/com.infonair.meetme.activity.photo.TakePhotoActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:2538)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2113)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2141)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2838)
at android.app.ActivityThread.access$1600(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3737)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:894)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1328)
at android.os.Parcel.readException(Parcel.java:1276)
at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:458)
at android.content.ContentResolver.notifyChange(ContentResolver.java:912)
at android.content.ContentResolver.notifyChange(ContentResolver.java:898)
at com.infonair.meetme.activity.photo.TakePhotoActivity.onActivityResult(TakePhotoActivity.java:154)
at android.app.Activity.dispatchActivityResult(Activity.java:3908)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2534)
... 14 more
java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1328)
at android.os.Parcel.readException(Parcel.java:1276)
at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:458)
at android.content.ContentResolver.notifyChange(ContentResolver.java:912)
at android.content.ContentResolver.notifyChange(ContentResolver.java:898)
at com.infonair.meetme.activity.photo.TakePhotoActivity.onActivityResult(TakePhotoActivity.java:154)
at android.app.Activity.dispatchActivityResult(Activity.java:3908)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2534)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2113)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2141)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2838)
at android.app.ActivityThread.access$1600(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3737)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:894)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
at dalvik.system.NativeStart.main(Native Method)

我也遇到了这个问题。使用这个意图时,几个设备(全部是SG)会随机崩溃,出现空指针异常,具体是在同一行代码(getContent().notifyChange(uri,null))。 - Frank
@Frank,你尝试过使用AsyncTask来执行这个操作吗? - Testo Testini

0

在解决这个问题时,我注意到在某些设备上拍摄的照片太大,甚至不能在 ImageView 上显示(有一个关于图像太宽以至于无法处理的警告),因此我开始调整大小以适合服务器使用。

我将发布整个代码(至少涉及拍摄和操作图片的部分),以防有帮助

这是调用意图的代码

 public void takePhoto() {

      String directoryPath = DCIM_PATH;
      this.pictureFileName = Long.toHexString(System.currentTimeMillis())+".jpg";
      String filePath = directoryPath + pictureFileName ;
      File directory = new File(directoryPath);

      if (!directory.exists()) {
          directory.mkdirs();
       }

       this.imageUri = Uri.parse(filePath);
       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       intent.putExtra( 
             MediaStore.EXTRA_OUTPUT,Uri.fromFile( new File(filePath) )
       );

       startActivityForResult(intent, TAKE_PICTURE);

 }

onActivityResult 中,我调用一个方法来处理新拍摄的照片。
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case TAKE_PICTURE:
               if (resultCode == Activity.RESULT_OK) {
                           loadImageJustTaken(imageUri);
               }
            break;
        }
 }

这是所述的方法

public void loadImageJustTaken(Uri selectedImage) {

        mActivity.getApplicationContext().getContentResolver().notifyChange(selectedImage, null);
        /*
         * process image to make its wide equals IMG_WIDTH constant, so that larger images will fit in ImageView
         */

         Bitmap b = BitmapHelper.decodeFileToScaledBitmap(new File(imageUri.getPath()), Tapabook.IMG_WIDTH);
        ivPicture.setImageBitmap(b);
        ivPicture.setVisibility(View.VISIBLE);
        System.gc(); 
 }

这里是我的BitmapHelper类的代码

public class BitmapHelper {


    private static final String LOGTAG = "BitmapHelper";

    public static File scaleBitmapFile(File f, int WIDTH) throws IOException{
            Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH);

            Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH);
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg ");
            b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream);

            File scaledBitmapFile = new File(Environment.getExternalStorageDirectory()
            + File.separator + "temp.jpg");
            Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" );
            scaledBitmapFile.createNewFile();
            Log.d(LOGTAG, "scaleBitmapFile file CREATED" );
            //write the bytes in file
            FileOutputStream fo = new FileOutputStream(scaledBitmapFile);
            fo.write(outStream.toByteArray());
            Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" );
            // remember close de FileOutput
            fo.close();
            Log.d(LOGTAG, "scaleBitmapFile file CLOSED" );

            return scaledBitmapFile;
    }

    public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){
            Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH);
            try{
                    //Decode image size
                    BitmapFactory.Options o = new BitmapFactory.Options();
                    o.inJustDecodeBounds = true;
                    BitmapFactory.decodeStream(new FileInputStream(f),null,o);

                    //The new size we want to scale to
                    final int REQUIRED_WIDTH=WIDTH;

                    final int ORIG_WIDTH  = o.outWidth;
                    final int ORIG_HEIGHT = o.outHeight;
                    Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]");
                    final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ;

                    //Decode with scaled height
                    Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap ");
                    return Bitmap.createScaledBitmap(
                                    BitmapFactory.decodeFile(f.getAbsolutePath()), 
                                    REQUIRED_WIDTH, 
                                    REQUIRED_HEIGHT, 
                                    false);
            }catch (FileNotFoundException e) {
                    Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage());
            }
            return null;
    }

    public static Bitmap scaleBitmap(Bitmap b, int WIDTH){
            final int REQUIRED_WIDTH=WIDTH;

            final int ORIG_WIDTH  = b.getWidth();
            final int ORIG_HEIGHT = b.getHeight();
            Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]");
            final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ;
            Log.d(LOGTAG, "scaleBitmap returning scaled bitmap ");
            return Bitmap.createScaledBitmap(
                            b, 
                            REQUIRED_WIDTH, 
                            REQUIRED_HEIGHT, 
                            false); 
    }
}

使用这个工具后,我再也不会在使用三星设备(无论是旧的手持设备如SG3 / Apollo还是新的平板电脑如SGTab 10.1)拍照时遇到问题了。希望它能有所帮助 :)


0

请查看此处的帖子 Content uri crashes camera on Android KitKat

一些旧的相机应用程序不支持 content:// URI,当传递一个不是 file:// URI 的 EXTRA_OUTPUT 时会崩溃。我在更新我的代码以支持 Android N+ 中的 FileProviders 时注意到了这个 bug。如果将 URI 更改为 file:// URI,对于 SDK 小于 Android N 的应用程序,您应该能够解决此问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接