Provide API to select a file on mobile

This commit is contained in:
fkloft
2014-01-20 22:33:00 +01:00
parent 9e210805dc
commit 787a68ac8d
3 changed files with 107 additions and 0 deletions

View File

@ -176,3 +176,18 @@ window.useAndroidPanes = function() {
return (typeof android !== 'undefined' && android && android.addPane && window.isSmartphone());
}
if(typeof android !== 'undefined' && android && android.getFileRequestUrlPrefix) {
window.requestFile = function(callback) {
do {
var funcName = "onFileSelected" + parseInt(Math.random()*0xFFFF).toString(16);
} while(window[funcName] !== undefined)
window[funcName] = function(filename, content) {
callback(decodeURIComponent(filename), atob(content));
};
var script = document.createElement('script');
script.src = android.getFileRequestUrlPrefix() + funcName;
(document.body || document.head || document.documentElement).appendChild(script);
};
}