I cant load HTML file into WebView from app specific storage since Android 11 (SDK30) - android-11

My App has the following use case:
We download a geojson file, a html file and some audio files from a server for a specific language a user has chosen and we are saving this in the app specific file directory.
The directory path is the following for each use case:
For the HTML file we have:
/storage/emulated/0/Android/data/my.example.com/files/ExampleApp/EnginePayload/de/html-file.html
For the json file we have:
/storage/emulated/0/Android/data/my.example.com/files/ExampleApp/LocationPayload/de/geojson-file.geojson
Audiodata:
/storage/emulated/0/Android/data/my.example.com/files/ExampleApp/Audio/de/intro.mp3
/storage/emulated/0/Android/data/my.example.com/files/ExampleApp/Audio/de/outro.mp3
and so on...
Since i have to change the minSDK and compileSDK to 30 i don't get the files to work.
I load the html-file.getAbsolutePath() to the webView but the webview client does not call ANY callback!
The audio files will not be started, because we use javascript functions to do that.
As i unterstand it, the app specific directory does not have to be changed because even on Android 11, the app has permission to read and write its own created files.
The moment i change it back to SDK 29, everything is working.
I don't know what to do. Can someone help me please?

I fixed it myself after hours!
My assumptions were right. The app had access to the files, because the app created them itself. so there was not an issue here to read the files...
Here is my fix and i hope it will help someone in the future:
There was something missing in the settings for the WebView.
webView.getSettings().setAllowFileAccess(true);
This allows me now to load a html file (with absolute Path) from the app specific directory for Android 11.
Here is my code:
webView.getSettings().setAllowFileAccess(true);
File extDir = cxt.getExternalFilesDir(null);
//htmlPath is something like this: "ExampleApp/EnginePayload/de/html-file.html"
File twine = new File(extDir.toString() + "/" + htmlPath);
webView.loadUrl(twine.getAbsolutePath());

Related

Bundling directory of images in app

Wondered if someone could help please:)
Titanium 5.5.0 sdk
Appcelerator 4.7.1
I need to be able to bundle a bunch of images in my iOS app and then get a directoryListing so the user can pick an image out of it.
In an older app I did this by placing my image directory in:
assets/iphone/[folder here]
and used this code:
var path = Ti.Filesystem.resourcesDirectory + '[nameoffolderhere]';
var imgDirectory = Ti.Filesystem.getFile(path);
var imagesArray = imgDirectory.getDirectoryListing();
and it worked. For some reason when I'm building a NEW app this no longer works. Indeed even the older app running under the latest SDK still finds the images. BUT using the exact same folder structure in a new app and it can't find the directory.
Could someone throw a light on the best place to place these directories so I can receive a directory listing and get to the images please?
thanks very much in advance
ade
Do you have <use-app-thinning>true</use-app-thinning> enabled in your tiapp.xml? If so, images are bundles with the asset-catalog are not accessible as files.
You should probably try to place them in app/platform/ios then, to copy them as resources instead of assets or disable app-thinning if you don't explicitly need it.

App Inventor sharing files No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 (has clip) (has extras) }

I'm a beginner at App Inventor and I don't know what I'm doing wrong with the sharing component. I'm trying to share a sound file but it gives me the following error:
No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 (has clip) (has extras) }
The code is the following:
I also tried the following things:
This doesn't work.
This reproduces the sound perfectly. That means that the picker works and the file exists.
I put a file in my root folder and it works but I want to send the file which was picked from the list which is in the following folder "/storage/sdcard0/MyDocuments/Downloads/app_inventor_1431867799168.mpeg".
I don't know where is the problem and I look in a lot of forums and none of the solutions solved my problem.
Thanks for your help.
PD: I just found that the downloaded files are stored in .MPEG format which it is a compressed format. It is possible that sharing function don't find any app that accept this type of format. If this is the problem please tell me what I have to do to make App Inventor to not change the original .mp3 file.
ok, problem solved as I said in the PD part the problem was that by default App Inventor stores the audio files in to MPEG format. This format is not recognized by whatsapp, gmail, etc...
Solution was to set a name to each file when I download them that ends with .mp3
With this extention the programs of my device recognize them and now I can share my audio files.
Thanks to everyone that was trying to solve this problem.

Reading JPG into BitmapData in ActionScript 3 (JPG is inside APK file)

I'm using Adobe AIR to make APK file for my Android phone. Inside the APK package there is a SWF file and in the same folder as the SWF file there is a subfolder named "images", which contains image.jpg.
I'm trying to read that image.jpg into the program at runtime but can't get the location of it (the program doesn't seem to find it.
Here's what I'm trying:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("images/image.jpg"));
while (bitmapData==null) {} //wait until loaded
return bitmapData;
The onComplete-function puts sets the bitmapData field. However, the COMPLETE event never happens so the while loop never exists.
I have also tried:
loader.load(new URLRequest("/images/image.jpg"));
loader.load(new URLRequest("app:/images/image.jpg"));
loader.load(new URLRequest("app-storage:/images/image.jpg"));
loader.load(new URLRequest("file:/images/image.jpg"));
None of it works.
I can't get this to work even when trying without the APK file, when only running the SWF file that is generated (the images subfolder is in the same folder as the SWF file).
I can't embed the JPG into the SWF file itself because I need to have a lot of image files and Flash CS6 runs out of memory when making such a big SWF file (reading the images externally would also mean a whole lot less compilation time).
Any ideas? How can I get put the external JPG file into BitmapData? Remember that the image is not outside of the APK file, it is packaged inside it.
Note: I'll also export the thing into a iOS ipa package later so it have to work there as well.
Edit because I can't self-answer due to my reputation.
Strille made me realize that the ActionScript Virtual Machine is single-threaded.
So it's impossible to make a thread sleep (wait) for an image being loaded. Instead I have to sigh rewrite a lot of code so that things are halted and continues when the onComplete function is called.
This thing that I tried before actually works but couldn't complete due to the while loop:
loader.load(new URLRequest("app:/images/image.jpg"));
If I remember correctly, you should be able to do it like this:
loader.load(new URLRequest(new File("app:/images/image.jpg").url));
Since we're using the File class, the above will not run in the Flash Player, just on iOS or Android.
From my experience there are two practical methods to load assets from a running Android APP using AIR
using URLLoader and .url property of the File instance
using FileStream (which receives a File instance)
Adding to project
You can package the files inside the APK using
the same technique as packaging ICONS, inside the .xml descriptor file for your app.
And make sure you add those to your IDE in the Android section (applies to IntelliJ and Flash Builder) "Files and folders to package"
- add the path to your wanted assets folder, and give it a relative name alias.
Elaboration
The assets themselves are placed (when the APP is installed),
inside the ''applicationDirectory'' which is available for AIR,
Yet since newer Android OS's, and Flash player security issues,
it is not possible to access those assets via the nativePath,
only the 'url' property of the File instance.
Best Practice
Use URLLoader and .url property of the File instance,
as it is also Asynchronous by nature and can resolve PNG / JPG files
using native decoder instead of having to do this manually
reading a FileStream (which returns a a ByteArray)
var f:File = File.applicationDirectory.resolvePath('images/myimage.png');
loader.load(new URLRequest(f.url));
and,
If I'm missing more ways, please let know... )

dynamic development with firefox

I am following a toolbar tutorial for firefox and i am unable to develop dynamically. I have changed the "install.rdf" file names with the .com and without the ".com". I have created a separate development profile as well. I created a text file with matching names in the tag. The text file contents had the absolute path of the folder. i placed it into the extension folder which is located in the profile. I started firefox but nothing happened. Noh toolbar was displayed. Can anybody help?
The link of the tutorial i am following is http://www.borngeek.com/firefox/toolbar-tutorial/chapter-4/
I cannot move forward without getting this working

Ruby app running on Sinatra using HAML, can't access files in uploads directory?

I have a Ruby app which is an Image Resizer. It uses the RMagick gem to do this. The app asks the user to upload a file, and then resizes it and saves the newly generated file.
It seems that Sinatra by default puts all uploaded files into the 'uploads' directory, and the newly generated file also seems to be saved there. I am assuming this is default behavior, not sure how to change this, but it isn't an immediate problem at the moment (although if you know how to do this, that would be appreciated too).
Now, in my 'success.haml' page which is displayed after the file is generated correctly, I am trying to display the newly generated image with a simple img tag. The path to the file is found in #filepath, so when I did:
%img(src=#filepath)
the HTML rendered (when inspected using Firebug) is correctly showing
<img src="uploads/filename.jpg">
and this file does indeed exist in my folder structure. However, the image appears broken.
Any ideas on how to overcome this problem?
Thank you.
Relative urls (uploads/filename.jpg) are called so because they are relative to web root. In Sinatra this is the public folder. By default it's located in your app directory and called public. But you can override that.
set :public_folder, 'my_root' # this will make my_root dir the web root.
So, to make your uploads visible to the internet, put them into your public folder.
Read this for more Sinatra settings and customizations.

Resources