【问题标题】:android application crash only in samsung device while getting image from camera从相机获取图像时,android应用程序仅在三星设备中崩溃
【发布时间】:2015-09-03 05:56:00
【问题描述】:

在我的应用程序中,我从相机获取图像。这段代码完全可以在大多数设备上运行,但是当我在 sumsung Galaxy Grand quattro 中测试时应用程序崩溃了。

这是我的尝试:

if(resultCode == RESULT_OK) {
    Bitmap photo = (Bitmap)data.getExtras().get("data");
    try {

        resized = Bitmap.createScaledBitmap(photo, 200, 200, true);
        final_image = Bitmap.createScaledBitmap(photo, 200, 200, true);
    } catch(Exception e) {
        Toast.makeText(getApplicationContext(), "Failed To Load ", 5000).show();
    }

    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if(currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT) {

        Bitmap blurredBitmap = BlurBuilder.blur(getApplicationContext(), resized);
        BitmapDrawable ob = new BitmapDrawable(getResources(), blurredBitmap);
        ll.setBackground(ob);

    } else {
        Bitmap blur = BitmapFactory.decodeResource(getResources(), R.drawable.blurback);
        BitmapDrawable ob = new BitmapDrawable(getResources(), blur);
        ll.setBackground(ob);
    }
    try {
        Bitmap circleimg = getCircularBitmapWithWhiteBorder(resized, 2);
        iv.setImageBitmap(circleimg);
        final_image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] b = baos.toByteArray();
        String encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
        imgpath = encodedImageString;
    } catch(Exception e) {
    }
}

注意:

I tasted my app in
  1. Micromax Canvas Knight - 奇巧
  2. 索尼 Xperia c3 - 棒棒糖
  3. Micromax 帆布 2-软糖

复杂工作中的设备上方

  1. 三星 Galaxy Grand quattro - jellybean(应用程序崩溃)

LogCat:

java.lang.RuntimeException: Unable to resume activity {com.example.camera/com.example.camera.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/50298 (has extras) }} to activity {com.example.camera/com.example.camera.MainActivity}: java.lang.NullPointerException
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2643)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2671)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2144)
    at android.app.ActivityThread.access$700(ActivityThread.java:143)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4960)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/50298 (has extras) }} to activity {com.example.camera/com.example.camera.MainActivity}: java.lang.NullPointerException
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3209)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2630)
    ... 12 more
Caused by: java.lang.NullPointerException
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:490)
    at com.example.camera.MainActivity.onActivityResult(MainActivity.java:93)
    at android.app.Activity.dispatchActivityResult(Activity.java:5387)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
    ... 13 more

【问题讨论】:

标签: android camera imageview


【解决方案1】:

崩溃的原因是数据为空。这发生在某些设备上,而是使用内容提供程序。数据将包含您可以读出的路径:

Bitmap photo;
if(data.getData() == null) {
    photo = (Bitmap)data.getExtras().get("data");
} else {
    photo = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
}

这应该适合你。

【讨论】:

  • 对我来说,它只反转三星(4.4.4)在其他像索尼(5.0),摩托罗拉(4.4.4和5.0)的情况下工作。
【解决方案2】:

这不是解决方案,但可以帮助隔离问题。

打开原生相机应用,选择较低的分辨率,例如 2Mpx,现在,打开您的应用并进行测试。

我使用 Cordova,当本机相机应用程序具有最高分辨率时,我意识到应用程序崩溃。

在尝试调整图像大小时可能是内存问题,因为它需要在内存中打开或在主存储中需要很大的缓存空间并且没有可用空间。

【讨论】:

    猜你喜欢
    • 2017-10-13
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2022-07-18
    • 2019-01-01
    • 1970-01-01
    相关资源
    最近更新 更多