【问题标题】:App crashes on capturing image/selecting image from gallery - Titanium Android应用程序在从图库中捕获图像/选择图像时崩溃 - Titanium Android
【发布时间】:2016-07-01 23:47:27
【问题描述】:

我正在尝试上传图片。以前,它一切正常。突然间,它停止在 Android 上运行。在 iOS 上测试了相同的代码,运行良好。

用例: 1. 单击一个按钮 - 打开相机(或从图库中选择) 2. 捕捉图像 3. 按“确定”按钮 - 应用程序崩溃

我清除了很多内存,认为某些设备可能存在内存问题。根据新的发行说明添加了相机权限,仍然面临问题。这是我的代码:

var dialog = Ti.UI.createOptionDialog({
    options : ['Camera', 'Gallery', 'Cancel'],
    title : 'Upload image using?'
});

dialog.show();

dialog.addEventListener('click', function(e) {

    if (e.index === 0) {

        //Open Camera
        Ti.Media.showCamera({
            saveToPhotoGallery : true,

            success : function(event) {
                console.error('UPLOAD IMAGE SUCCESS ', JSON.stringify(event));
                callback(event.media);
            },

            cancel : function(err) {
                console.error('UPLOAD IMAGE CANCEL ', JSON.stringify(err));
            },

            error : function(err) {
                console.error('UPLOAD IMAGE ERROR ', JSON.stringify(err));
            },

            showControls : true,
            mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO,
            autohide : true
        });
    } else if (e.index === 1) {

        //Open gallery
        Ti.Media.openPhotoGallery({
            success : function(event) {
                console.error('UPLOAD IMAGE SUCCESS ', JSON.stringify(event));
                callback(event.media);
            },

            cancel : function(err) {
                console.error('UPLOAD IMAGE CANCEL ', JSON.stringify(err));
            },

            error : function(err) {
                console.error('UPLOAD IMAGE ERROR ', JSON.stringify(err));
            },
        });
    } else {
        // Do nothing
    }
    dialog.hide();
});

tiapp.xml

<manifest>
    <uses-permission android:name="android.permission.CAMERA" />
</manifest>

谁能告诉我代码有什么问题或者我需要添加什么吗?

一些日志:

[DEBUG] :  skia: --- SkImageDecoder::Factory returned null
[DEBUG] :  skia: --- SkImageDecoder::Factory returned null
[DEBUG] :  skia: --- SkImageDecoder::Factory returned null
[DEBUG] :  skia: --- SkImageDecoder::Factory returned null
[DEBUG] :  skia: --- SkImageDecoder::Factory returned null
[DEBUG] :  Window: Window is closed normally.

【问题讨论】:

  • 你能发布你的Logcat吗..
  • 崩溃时我没有得到任何调试日志。
  • 添加了一些我在崩溃前得到的日志

标签: android titanium android-camera titanium-mobile


【解决方案1】:

为了解决这个问题,我需要做两件事。

  1. 在 tiapp.xml 中添加这个

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

  2. 打开设置>应用程序>相机

    • 强制关闭,然后清除数据和缓存
    • 重启手机

这个我曾经解决过,它开始工作了。

【讨论】:

  • 我相信这是相机本身的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多