android


How can I ensure that my Android 6 Cordova app prompts the user to give permission before attempting to access the filesystem?


I am upgrading a Cordova 3.4 application to Cordova 6.0 at the same time as upgrading the deployment platform (Nexus tablets) from Android 4.4 to Android 6. As part of this I've upgraded the filesystem plugin cordova-plugin-file from v0.2.5 to v4.1.1
The application creates a directory structure of 10 folders on the shared filesystem (file:///storage/emulated/0/) upon first run. I've added the following preference to config.xml to ensure the same location is used in the new version of the app:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
I'm aware that there is a new permission model in Android 6 where the user has to separately allow each permission that the application requests.
If the device is running Android 6.0 (API level 23) or higher, and the
app's targetSdkVersion is 23 or higher, the app requests permissions
from the user at run-time.
Android Developer documentation
When installed on tablets that have had an earlier version installed (and since uninstalled) and which have had the directory structure created, the new version of my app performs as expected upon first run, prompting the user to allow permission to access the file system.
However, when installed upon a tablet which has never had the app installed before (or when I remove the directory structure created by an earlier version) the app fails by throwing the FileError.PATH_EXISTS_ERR error. It does not prompt the user to allow permission to access the file system as expected.
I've checked that when the application is built, the generated AndroidManifest.xml does contain the necessary permissions attribute:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
My current workaround is to stop the app, navigate to Settings > Apps > MyApp > Permissions and manually enable the "Storage" permission before running the app again. But I really don't want my users to have to do this!
How can I ensure that the app does prompt the user to give the required permission before actually attempting to access the filesystem?
Here are some samples of my code:
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 4000 * 1024 * 1024, gotFileSystem, errorHandler);
function gotFileSystem(fileSystem) {
// store reference to file system
fs = fileSystem;
}
function createDir(directoryName) {
var directoryCreated = when.defer();
fs.root.getDirectory(directoryName, {
create: true
}, function (dirEntry) {
directoryCreated.resolve();
}, function(e) {
directoryCreated.reject(e);
}
);
return directoryCreated.promise;
}
Faced the exact same issue after upgrading to Android 6 (MArshmallow). Cordova file plugin (v 4.1.1) has permission issue with Android Marshmallow. This issue will not allow folders to be created in android filesystem resulting in path exist error. This issue is fixed now. You may have to pull the latest FileUtils.java from android src folder in cordova file plugin github to make this work. Once you updated the plugin, at first access to file system, the app requests for the access permission from user. Subsequent requests works fine from then on. Check CB-10798 in Apache issue tracker for info on this. Hope it helps

Related Links

Load Bitmap with AsyncTask onPostLoad
How to solve for viewpager : The specified child already has a parent. You must call removeView() on the child's parent first
Additional Text field appear in Tumblr (tumblr API using OAuth) login page in Android version 4?
Hiding the ActionBar on RecyclerView/ListView onScroll
Underline a dynamically generated TextView in android
Android Application Name getting truncated
Android facebook graph api add place or location params with photo upload
Flickr JSON Parsing in Android
Find a Random Picture from Gallery
How to make EditText not change it's size automatically
Mobile app as3 vs html5
Where can I read WiFi packet loss counters from Android device?
Android ndk-build failed
Is there Android support for Clojure? [duplicate]
Holo-themed App falls back to default Android theme
Not getting zipcode from Latitude and Longitude

Categories

HOME
phantom-dsl
microsoftgraph
hyperlink
c99
jmeter
css3
case
3d
zend-framework
apache-spark-mllib
can
jetty
python-multithreading
joomla3.0
computer-science
php-5.6
frequency-distribution
renjin
do-while
coin3d
feathersjs
chargify
easyphp
spring-async
backpack-for-laravel
named-entity-recognition
joptionpane
surveymonkey
android-maps
exchangewebservices
calculation
custom-controls
livelink
kudu
powershell-ise
zend-debugger
utorrent
kodi
catch-unit-test
sammy.js
contacts
indy10
least-squares
protege4
watchman
loading
news
azure-arm
android-softkeyboard
lpsolve
smoothstate.js
berkeley-db-je
jide
getchar
fwrite
tinymce-3
posixct
remedy
static-cast
colorbar
reshape
java-websocket
cudd
grails-plugin
custom-lists
clipboard.js
yajsw
avisynth
xenomai
phonertc
extjs-grid
dronekit-android
alloy-ui
teamcity-9.1
showdialog
boost-program-options
psr-4
build-script
ray
process-explorer
asplinkbutton
sqlclr
nokia-s40
adobe-media-server
listitem
stress
user-tracking
filemerge
google-floodlight
pylucene
twitterizer
photolibrary
cac
diagrams
squishit
cruisecontrol.rb
updatesourcetrigger
pagemethods
spread
leader

Resources

Encrypt Message