问题
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