I am trying to load local HTML (that exists in the project's folder structure) in an instance of webStageView. While this works fine in windows and ipad/iphone - it fails to locate the files in Android (only tried it in 2.2)
File.applicationDirectory.url returns "app:"
File.applicationStorageDirectory.url returns "app-storage:"
File.applicationDirectory.nativePath returns an empty string, as specified in Adobe's documentation.
The problem is that the webview gives a "Web page not available, app:/test/index.html not found" error. Is there a way to get the full path, or to "force" the browser to understand that app: refers to a specific folder?
Thanks!
As Adobe help states:
The app: and app-storage: schemes are not supported.
On iOS your code works perfectly, but on Android, you have to achieve it with some hacky implementation like yours, because security issues related to StateWebView loading urls from those directories. Another solution is to copy your app: or app-storage: file into a temporary one and load that temp file url into StageWebView:
var htmlFile:File = File.applicationDirectory.resolvePath(url);
var workingFile:File = File.createTempFile();
htmlFile.copyTo(workingFile, true);
stageWebView.loadURL(workingFile.url);
Edit: Another solution could be to have your html content coded into an .as file and use StageWebView.loadString() method. Having in mind that you have to encode that string for Android devices.
I fix this problem a couple of days a go. The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html. Notice the three slashes; the hostname part of the URL is empty, so the slash at the beginning of the path immediately follows the double slash at the beginning of the URL. You will also need to expand the user's path; ~ does no expand in a file: URL. So you would need file:///home/User/2ndFile.html (on most Unixes), file:///Users/User/2ndFile.html (on Mac OS X), or file:///C:/Users/User/2ndFile.html (on Windows).
This solution work perfectly in my app.
Related
I have a web app with a file upload form that works fine with every combination of browser/file system except Chrome reading from a mounted Android or iOS device (HFS and DCF file systems). Using a 3rd-party jQuery event handler (ajaxupload), it reads the filename from HTMLInputElement.value for a simple file extension check before uploading.
The different strings I'm seeing are:
IE/Android: "C:\Users\username\AppData\Local\Microsoft\Windows\INetCache\IE\DAG5BXZ2\filename.jpg"
Edge/Android: "filename.jpg"
Firefox/Android: "C:\fakepath\filename.jpg"
Chrome/USBDrive: "C:\fakepath\filename.jpg"
Chrome/Android: "C:\fakepath\{C8BCC7E6-C108-D148-F5FF-3BC3EB92E793}"
How/why is Chrome handling these file systems different than the others? Is there any way to change it or work around it? All I need is the file extension.
Update: It appears that Chrome is trying to operate on a temporary path/file it has created but which is not valid. The FileList object is valid and I can access file[0] - it has a .name (the UUID string), a .lastmodifieddate (when the user clicked 'Open' - not the actual file's date), .size is 0, and .type is undefined.
For future reference: This was a bug in Chrome that was introduced by modifications to the filepicker to allow uploading remote files. It was fixed sometime during March, 2019.
I am developing an app in Android and there only one module is from Unity. I am downloading all data from server and save it in path with the method returns below.
getFilesDir().getPath()
Now in Unity, I want to get a json file from the directory and load the image in unity. But I am unable to get /data/data/PACKAGE_NAME from unity. Instead of that I am getting /Storage/Emulated/0/Android/data.I am using Application.persistentdata to get Android path. How to get /data/data path in Android. Please help me to resolve this. I am trying this for more than a week.
I am currently working on something exactly like this and for me, it's working properly. The steps are:
Get the image path. The Application.persistentdata is exactly what you need.
Know beforehand the name of the file/image you want to access with its extension also (for e.g. - fish.png / manifest.json).
Add the file/image name to the image path right before accessing it through WWW call.
These steps will suit your need. Let me know if you get any problem in any of the aforementioned steps.
If you know the exact path that should be read, why don't you read the file with normal methods?
using System;
StreamReader sr = new StreamReader("data/data/.../a.txt");
string content = sr.ReadToEnd();
sr.Close();
However if you know the file's path in only Java side, then you can comminicate between Java and C# codes using UnitySendMessage, or AndroidJavaObject etc..
Excuse me?
I pushed the file 'proxy.pac' to sdcard using this command:
adb push C:\Users\zuokang.li\Documents\proxy.pac /sdcard/
I try to set proxy auto config in android. So I set pac url "file:///sdcard/proxy.pac".But it cannot work.
I don't know whether it is set right. Can you help me ? Thanks!
Apparently Android doesn’t accept setting a local PAC file (127.0.0.1 doesn't seem to work either) and may even cause browser crashes for an invalid proxy port (-1). Therefore either
Use http://some_host/proxy.pac and store the file on some host, or
Use Firefox for Android and the exact same settings you used above (verified) - see https://www.topbug.net/blog/2015/03/02/configure-proxy-using-pac-files-on-firefox-for-android/ for info.
I experienced the same issue with my android phone, and searching for a solution I noted that the only one is to access to a web server for getting the .pac file (as Roy explains). But I wanted the solution (all about this) locally in my phone.
I installed a thin web server in my phone called SimpleHttpServer from Google Play and proceed as you do to set the .pac file using the URL provided by the web server (previously, I created a directory, located the .pac file inside it and pointed the web server root folder to that directory).
Additionally, I installed Simple Text Editor for .pac file edition and everything works as expected.
For use a PAC file in Android you can use Drony, looks ugly, but works! Even if you need authentication.
https://play.google.com/store/apps/details?id=org.sandroproxy.drony
Since file:/// is disabled on Android, you can convert the pac file to base64 and use this format:
data:application/x-ns-proxy-autoconfig;base64,
I'm currently using a Corodova plugin inappbrowser to open files. It's working fine on iOS but not on Android. I found out that Android's browser doesn't support viewing files, so you have to use the system.
The problem I'm having, I think, is that I don't know the how to get the path to the file.
Here's my code:
$scope.onResourceClick = function(url){
window.open(url, '_system', 'location=no');
};
url is the relative path to the file, from the index.html in www folder.
So I think my question is, how do I get the absolute path to the file.
I'm making progress. Using Cordova's file plugin I can get a few different paths. Still unsure which to use and where exactly the file is being stored at.
I'm using cordovaFile.checkFile to check if there is a file at the path I try, and I'm just kinda guessing for now to see if I can get lucky and find it.
$cordovaFile.checkFile(cordova.file.dataDirectory, url)
.then(function (success) {
alert('yay' + success);
}, function (error) {
alert('nah' + error);
});
I've tried
cordova.file.dataDirectory
cordova.file.applicationDirectory
and appending to the end of each of those, the path from the www folder to my file, and just the file name. I'm hoping I can get lucky and find the right combination to the file, because I can't seem to find an answer researching.
Edit:
The workflow for what I'm trying to do has changed.
I'm now storing the files on a server and using an api to return the url to the file. Then downloading the file onto the device, and then opening it.
Currently I have everything except the download method working.
$cordovaFile.writeFile(cordova.file.externalDataDirectory, resourceFullName, resource.DocumentURL, true)
The download method is only downloading 100bytes of the file.
I think this may be because the writeFile method is asking for Data, and I'm giving it the URL to the file, rather than txt. It looks like my current question is, how do I download a file to the device.
There are a couple of other issues you may be having:
The system browser may not have permission to open files in your application's www directory.
I don't believe Android's browser supports PDFs or Powerpoints. As Murtaza suggested, there are plugins that will allow you to open documents in another app. You could also look into pdf.js to render PDFs in a webview.
For downloading files you should use the file transfer plugin. http://ngcordova.com/docs/plugins/fileTransfer/
Use the following File Opener Plugin
Sample Use
window.plugins.fileOpener.open("file:///sdcard/Android/data/com.example.application/manual.pdf");
I have a very simple html page on our local intranet, would like others to be able to click a link to download an APK file so that they can beta test on their Android devices.
Here's the HTML:
<a href="//intranet/files/myapp.apk" >
If I click on the link I get:
"404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable."
If I right click on the link and choose "Save target as..." it opens a dialog with the file name as "myapp_apk" (replaced the "." with "_")
If I double click on the APK file in Windows Explorer it opens it as an installer, so it seems like a valid extension.
Is there some trick to get that to do a download?
Thanks.
not 100% sure, but i think you're loading that file via SMB, or file-sharing, which is fine, but not suitable for your purposes.
Since you have this page on a intranet server, you should put the APK on the same (web) server and link to it that way. this means that you should be able to write a url to access the file ( sort of like this http://my_intranet_server/my/path/to/the/file.apk )
hope this helps
Add the APK file extension into the MIME types found under IIS manager.