简体   繁体   English

Android-Go上的MediaStore.ACTION_IMAGE_CAPTURE

[英]MediaStore.ACTION_IMAGE_CAPTURE on Android-Go

I have this app that was working perfectly until the business using the app bought everyone Huawei Y5lite running android go , then the app started crushing while taking images. 我拥有一个运行良好的应用程序,直到使用该应用程序的企业购买了每个运行android go的华为Y5lite,然后该应用程序在拍摄图像时开始崩溃。 I have been trying to crack this the last four days but without success. 最近四天我一直在努力破解,但没有成功。 The crashes are random and do not follow any pattern, meaning the app can take several images without crashing then at some point crash which makes me think my activity is being killed when in background and camera on the foreground and so onActivityResult fails. 崩溃是随机的 ,不遵循任何模式,这意味着该应用程序可以拍摄几张图像而不会崩溃,然后在某个时刻崩溃,这让我觉得我的活动在背景和前景中的摄像头时被杀死,因此onActivityResult失败。 i have tried to save the image URL onSaveInstanceState and retrieve it onCreate but doesn't solve it below is my relevant code and errors 我试图保存图像URL onSaveInstanceState并在onCreate上检索它,但下面没有解决它是我的相关代码和错误

private void launchCamera() {


        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

            File photoFile = null;
            try {
                photoFile = BitmapUtils.createTempImageFile(this);
            } catch (IOException ex) {

                ex.printStackTrace();
            }
            if (photoFile != null) {


                mTempPhotoPath = photoFile.getAbsolutePath();

                // Get the content URI for the image file
                Uri photoURI = FileProvider.getUriForFile(this,
                        FILE_PROVIDER_AUTHORITY,
                        photoFile);

                // Add the URI so the camera can store the image
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);

                // Launch the camera activity
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
    }

//saving the filename incase activity is killed
@Override
    public void onSaveInstanceState(Bundle bundle)
    {
        super.onSaveInstanceState(bundle);
        bundle.putString("fileName", mTempPhotoPath);
    }
//retrieving file name onCreate
if (savedInstanceState != null){
            mTempPhotoPath = savedInstanceState.getString("fileName");}

// processing the image

private void processAndSetImage() {


    switch (imageTaken) {
        case "imageOne":
//I did the try-catch to see if I can isolate the issue but still crashes
                try{
                mAddImageOne.setVisibility(View.GONE);
                mResultsBitmap = BitmapUtils.resamplePic(this, mTempPhotoPath);
                mOneView.setVisibility(View.VISIBLE);
                mOneView.setImageBitmap(mResultsBitmap);
                findViewById(R.id.front_image_text).setVisibility(View.VISIBLE);
                findViewById(R.id.save_cancel).setVisibility(View.VISIBLE);
                }catch (Exception e){
                    Toast toast = Toast.makeText(getApplicationContext(), "Please try take the picture again",
                            Toast.LENGTH_LONG);

                    toast.setGravity(Gravity.BOTTOM, 0, 1100);
                    toast.show();
                }
                break;


            case "imageTwo":
                try{
                mAddImageTwo.setVisibility(View.GONE);
                mTwoView.setImageBitmap(mResultsBitmap);
                mResultsBitmap = BitmapUtils.resamplePic(this, mTempPhotoPath);
            findViewById(R.id.front_image_label_text).setVisibility(View.VISIBLE);
            findViewById(R.id.save_cancel).setVisibility(View.VISIBLE);
            mTwoView.setVisibility(View.VISIBLE);
            }catch (Exception e){
                Toast toast = Toast.makeText(getApplicationContext(), "Please try take the picture again",
                        Toast.LENGTH_LONG);

                toast.setGravity(Gravity.BOTTOM, 0, 1100);
                toast.show();
            }


    break;
}

Below is the error I am getting when the crash occurs. 以下是崩溃发生时出现的错误。 (Sometimes the photo taking and processing occurs well, sometime the crash happens) (有时照相和处理很好,有时会发生崩溃)

02-05 13:53:22.139 23081-23086/com.avigail.tuborg I/zygote: Do partial code cache collection, code=25KB, data=30KB 02-05 13:53:22.140 23081-23086/com.avigail.tuborg I/zygote: After code cache collection, code=25KB, data=30KB 02-05 13:53:22.141 23081-23086/com.avigail.tuborg I/zygote: Increasing code cache capacity to 128KB 02-05 13:53:22.277 23081-23081/com.avigail.tuborg D/AndroidRuntime: Shutting down VM 02-05 13:53:22.284 23081-23081/com.avigail.tuborg E/AndroidRuntime: FATAL EXCEPTION: main Process: com.avigail.tuborg, PID: 23081 java.lang.RuntimeException: Unable to resume activity {com.avigail.tuborg/com.avigail.kaskazi.activities.StockistActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.avigail.tuborg/com.avigail.kaskazi.activities.StockistActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference at android.app.Activ 02-05 13:53:22.139 23081-23086 / com.avigail.tuborg I / zygote:执行部分代码缓存收集,代码= 25KB,数据= 30KB 02-05 13:53:22.140 23081-23086 / com.avigail。 tuborg I /合子:代码缓存收集后,代码= 25KB,数据= 30KB 02-05 13:53:22.141 23081-23086 / com.avigail.tuborg I /合子:将代码缓存容量增加到128KB 02-05 13:53 :22.277 23081-23081 / com.avigail.tuborg D / AndroidRuntime:关闭VM 02-05 13:53:22.284 23081-23081 / com.avigail.tuborg E / AndroidRuntime:致命例外:主进程:com.avigail.tuborg ,PID:23081 java.lang.RuntimeException:无法恢复活动{com.avigail.tuborg / com.avigail.kaskazi.activities.StockistActivity}:java.lang.RuntimeException:无法传送结果ResultInfo {who = null,request = 1 ,结果= -1,数据=空}到活动{com.avigail.tuborg / com.avigail.kaskazi.activities.StockistActivity}:java.lang.NullPointerException:尝试调用虚拟方法'int java.lang.String.hashCode ()”位于android.app.Activ上的空对象引用上 ityThread.performResumeActivity(ActivityThread.java:3844) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1777) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:6861) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:450) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.avigail.tuborg/com.avigail.kaskazi.activities.StockistActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' o android.app.ActivityThread.-wrap11(-)上的ityThread.performResumeActivity(ActivityThread.java:3844)在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884)在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053) android.os.Looper.loop(Looper.java :)上android.os.Handler.dispatchMessage(Handler.java:106)上android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1777)的未知来源:0): 166)在android.app.ActivityThread.main(ActivityThread.java:6861)在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:的java.lang.reflect.Method.invoke(本机方法)处450)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)原因:java.lang.RuntimeException:无法传递结果ResultInfo {who = null,request = 1,result = -1,data = null}到活动{com.avigail.tuborg / com.avigail.kaskazi.activities.StockistActivity}:java.lang.NullPointerException:尝试调用虚拟方法'int java.lang.String.hashCode()'o n a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:4564) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1777) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:6861) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:450) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference at com.avigail.kaskazi.activities.StockistActivity.processAndSetImage(StockistActivity.java:392) 在android.app.ActivityThread.deliverResults(ActivityThread.java:4564)处的null对象引用在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816)在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884)在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1777)位于android.app.ActivityThread.-wrap11(Unknown Source:0)位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1777)在java.lang.reflect.Method上的.Handler.dispatchMessage(Handler.java:106)在android.os.Looper.loop(Looper.java:166)在android.app.ActivityThread.main(ActivityThread.java:6861)处。在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)处com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:450)处调用(本机方法)原因:java。 lang.NullPointerException:尝试在com.avigail.kaskazi.activities.StockistActivity.processAndSetImage(StockistActivity.java:392)上的空对象引用上调用虚拟方法'int java.lang.String.hashCode()' com.avigail.kaskazi.activities.StockistActivity.processAndSetImage(StockistActivity.java:392) at com.avigail.kaskazi.activities.StockistActivity.onActivityResult(StockistActivity.java:377) at android.app.Activity.dispatchActivityResult(Activity.java:7393) at android.app.ActivityThread.deliverResults(ActivityThread.java:4560) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1777) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:6861) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:450) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) com.avigail.kaskazi.activities.StockistActivity.processAndSetImage(StockistActivity.java:392)com.avigail.kaskazi.activities.StockistActivity.onActivityResult(StockistActivity.java:377)在android.app.Activity.dispatchActivityResult(Activity.java:7393)在android.app.ActivityThread android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816)的android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884)的android.app.ActivityThread.handleLaunchActivity(ActivityThread。)的.deliverResults(ActivityThread.java:4560) java:3053)位于android.app.ActivityThread.-wrap11(未知来源:0)位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1777)位于android.os.Handler.dispatchMessage(Handler.java:106 )的android.os.Looper.loop(Looper.java:166)的com.java.lang.reflect.Method.invoke(本机方法)的android.app.ActivityThread.main(ActivityThread.java:6861)的com.android。在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:450) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

I will highly appreciate your help PS: I have see the various questions addressing the issue but none of the answers worked including checking if data is null(my data is null because am putting the extra option), saving the image URL onSaveInstanceState, znc checking if the intentfor result returns ok 非常感谢您的帮助PS:我看到了解决该问题的各种问题,但没有一个有效的答案,包括检查数据是否为空(我的数据为空,因为要添加额外的选项),在onSaveInstanceState上保存图像URL,znc检查如果意图结果返回确定

This turned out to be a rather silly mistake that cost me several days. 原来这是一个很愚蠢的错误,使我花费了几天的时间。 The problem as i had anticipated was my activity being killed while in the background, and the solution was properly saving the state. 如我所料,问题是我的活动在后台被杀死,解决方案正确地保存了状态。

I was saving the imageUrl, alright, but was missing on the variable in the switch that was checking which image had been captured 我当时保存的是imageUrl,但是在交换机中检查正在捕获哪个图像的变量上丢失了

switch (imageTaken) {
        case "imageOne":

So adding the variable onSaveInstanceState and calling it appropriately onCreate solved the problem 因此,添加变量onSaveInstanceState并适当地对其进行调用就可以解决问题

@Override
    public void onSaveInstanceState(Bundle bundle)
    {
        super.onSaveInstanceState(bundle);
        bundle.putString("fileName", mTempPhotoPath);
        bundle.putString("imageTaken", imageTaken);
    }

If you find yourself here because of a similar issue, check that there is no variable that will not be initialized with a value incase your activity is recreated. 如果您因类似问题而在这里,请检查是否没有变量会被重新创建,以防重新创建活动。

The upside is that the whole problem helped optimize my image sizes, and memory usage during bitmap processing 好处是,整个问题有助于优化我的图像大小以及位图处理期间的内存使用率

暂无
暂无

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

相关问题 MediaStore.ACTION_IMAGE_CAPTURE - MediaStore.ACTION_IMAGE_CAPTURE Android MediaStore.ACTION_IMAGE_CAPTURE和Intent.ACTION_PICK - Android MediaStore.ACTION_IMAGE_CAPTURE and Intent.ACTION_PICK 在Android中使用MediaStore.ACTION_IMAGE_CAPTURE意图捕获图像 - capturing images with MediaStore.ACTION_IMAGE_CAPTURE intent in android MediaStore.ACTION_IMAGE_CAPTURE提供NullPointerException - MediaStore.ACTION_IMAGE_CAPTURE giving NullPointerException 具有action =“ MediaStore.ACTION_IMAGE_CAPTURE”的意图的类别是什么? - What is the class for the intent with action = “MediaStore.ACTION_IMAGE_CAPTURE”? android通过MediaStore.ACTION_IMAGE_CAPTURE拍照-指定图像大小 - android taking picture by MediaStore.ACTION_IMAGE_CAPTURE - specifying image size Android:使用MediaStore.ACTION_IMAGE_CAPTURE时如何定义图像参数(大小?格式?文件大小) - Android: how to define image parameters (size? format? filesize) when using MediaStore.ACTION_IMAGE_CAPTURE 如何在 Android 10 及更高版本中通过意图 MediaStore.ACTION_IMAGE_CAPTURE 获取图像 URI - How to get Image URI by intent MediaStore.ACTION_IMAGE_CAPTURE in Android 10 and above Android 问:意图(MediaStore.ACTION_IMAGE_CAPTURE) - 未找到处理意图的活动 - Android Q: Intent(MediaStore.ACTION_IMAGE_CAPTURE) - No Activity found to handle Intent 从Intent(MediaStore.ACTION_IMAGE_CAPTURE)获取图像uri - get image uri from Intent(MediaStore.ACTION_IMAGE_CAPTURE)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM