Titanium Android showCamera error unable to create file for storage

醉酒当歌 提交于 2019-12-12 05:47:38

问题


I am trying to use the device camera in my application , but there is an error shows up and the camera is not shown. The error is

unable to create file for local storage

My Controller code is

   function choosePhotoDialogClicked(e) {
        if (Ti.Media.hasCameraPermissions) {
            openCamera();
       }else {
            alert("No camera permission. Asking for Permission");
            Ti.Media.requestCameraPermissions(function(e) {
                alert('request result'+JSON.stringify(e));
                if (e.success === true) {
                    openCamera();
                } else {
                    alert("Access denied, error: " + e.error);
                }
            });
        }
    }
    function openCamera(){
        Ti.Media.showCamera({
          allowEditing: true,
          saveToPhotoGallery: true,
          mediaTypes: [Titanium.Media.MEDIA_TYPE_PHOTO],
          success: function(event) {

            writeFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, 'ana.png');
            writeFile.write(event.media);
            $.addNewPhoto.setTitle('اضافة صورة اخرى');

          },
          error: function(error) {
            alert('showcamera error ->'+JSON.stringify(error));
            //alert('خطأ في اعدادات الكاميرا');
          }
        });
    }

and the tiapp.xml manifist code

    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
            <uses-permission android:name="android.permission.CAMERA" />
            <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
            <uses-feature android:name="android.hardware.camera" />
            <uses-feature android:name="android.hardware.camera.autofocus" />

            <application>
                <activity   
                android:name="ti.modules.titanium.media.TiCameraActivity"  
                android:configChanges="keyboardHidden|orientation"  
                android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
            </application>
            <application android:theme="@style/Light"/>
            <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
        </manifest>
    </android>

Any help will be appreciated


回答1:


It's an issue with Android Permissions, Fokke and the team did a blog on this a few months ago for Marshmallow.



来源:https://stackoverflow.com/questions/37892975/titanium-android-showcamera-error-unable-to-create-file-for-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!