0

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

Mahmoud Gamal
  • 45
  • 1
  • 7

1 Answers1

0

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

  • Thanks for reply , i have just solved the problem , the issue was i must add overlay , i do not why , but it seems it is necessary for android , but there is anew issue i encountered , the camera overlay works but when i take the photo i get "error code=-1, file==null" – Mahmoud Gamal Jun 19 '16 at 01:48