2016-03-16 90 views
0

我想上传图片。以前,它一切正常。突然间现在它停止在Android上工作。在iOS上测试相同的代码,工作正常。应用程序崩溃,从画廊 - 钛的Android

使用案例: 点击一个按钮 - 打开相机(或可从库中选择) 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. 
+0

logcat的请留言。 –

+0

您可以发布您的logcat .. –

+0

而崩溃,我没有得到任何调试日志。 – Porwal

回答

0

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

  1. 在tiapp.xml添加此

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

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

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

这是我用来解决,并开始工作。

+0

之前,我相信这是与相机本身的问题。 – Porwal