Open a html file from within an Android App - android

I am almost complete building a stocktaking app for work, but there is one thing stumping me at the moment. Firstly, I am a .net developer and so have had no previous Java experience prior to this app, so everything has been learnt on the fly.
Ok, so I have put together a "help" page for the users. Its in HTML. I have created a folder on my nexus 7 and named it saregohelp (the app name is Sarego). I have placed the html file inside and its named "help.html"
Here is my current link.
"file://Internal storage/saregohelp/help"
I can get the button to link to a website, but the tablets wont have web access so the html file needs to be local.
Any ideas?
Thank you!

You can put the html file in assets.

Related

img not displaying on Android

I have a simple image in my html which renders fine on my PC, but not on my smartphone:
<div id="welcomebox">
<img src="geschenk.jpg"/>
</div>
my folder-structure is as follows:
C:/Maus
- index.html
- geschenk.jpg
on my smartphone I copy that folder to my download-folder and open index.html from there. There's no web-server included, I directly open the file from the filesystem.
But on my smartphone the image isn't displayed.
Chrome will receive a content scheme from the Files app like:
content://com.google.android.apps.nbu.files.provider/1/file:// ...../index.html
As soon as Chrome 'sees' a content scheme it cannot display pictures as even if Chrome changes the scheme to:
content://com.google.android.apps.nbu.files.provider/1/file:// ...../geschenk.jpg
the provider will not let it access as there is no read permission for it.
The Android filesystem structure can't open relative file paths the same way other systems do.
So the answer is you need to use a complete hardcoded file:/// path.
This is not a very good approach since you need to replace all the URLs/paths in your HTML files.
Another approach if you are determined to do so, you can upload all project resources such as images, CSS, javascript to the cloud, like using SDN to access those files and to let the project work. But using the SDN approach it's easier to upload everything including the HTML files to a hosting account.

Trusted Web Activity: Is it possible to add file association

I have been able to successfully create a TWA from the base instructions provided. It links to the website and works as expected.
However, one of the functionalities of the web app is to upload a particular file type (which is a type of zip) and display its content. That functionality too works as expected and one is able to upload the file, say from the downloads directory to the app and it displays.
What would be desirable is: for the user to tap on the file from the directory (say downloads) and it opens in the App. I am aware of the limitations of access a local file in any web app. But before I tackle that issue I would like to know if there is a way to associate that file extension (or mime-type) with the app. And more importantly how to at least get the path of the file. In the current setup there is no custom Activity java code written. I went by the documentation and put the right settings in the manifest.xml and the site gets loaded.
Thanks.
This is possible by implementing Web Share Target in your Progressive Web App, then enabling it in our Trusted Web Activity.
When using Bubblewrap it will to automatically configure the Trusted Web Activity on init.

Update offline webpages without updating app

I have an app which contains html files which i am displaying using a webview. This html files are nothing but documentation the users of my app require. My question is, can I update these html files without asking the user to update the entire app? I dont want to replace these html files by hosting the documentaion online.
You will have to do one of these:
Update your app (which is what you don't want)
Host the raw .html files on a web server, and whenever the user opens the app, check if there are new files available and download them.
Simply create a website that shows the .html files and open the
website in your app (which i'm guessing is what you don't want
either)
So you're left with option 2.
To update files without requiring an app update, you will need the app to obtain the HTML content online.
One option, which you mentioned you don't want, is loading a URL into the WebView rather than local HTML files.
The other option would involve hosting the web pages somewhere and the app would download them. The only benefit of this I can see, is that if the device is offline is can use the last obtained HTML file. You could just use caching to achieve this though.
How complicated are the webpages? Using JSON is another method.

How to load a .pdf or a .doc file in android

I want to show a pdf (preferably) or a word document in my app; like a privacy notice screen. Many applications have it, so it should be possible. i tried loading a simple text file as a start but doesn't provide formatting, fonts or trade mark symbols. I've gone through a few posts but I couldn't apply it to my app. Could anyone tell me how is it done? Could I store the file somewhere in res folder and provide a path to open it through my code? I looked into the following link but I'm not sure if that's the right approach in my case android: open a pdf from my app using the built in pdf viewer.
Android does not support opening PDF and DOC files natively. You'd have to make your own implementation.
Like t0mm13b said, you should consider using HTML (+ CSS) instead and use a WebView.

what is the problem with android while downloading? can any one figure out?

The following link downloads a file from a site.it works fine in desktop browser. but it is not working in android default browser and in webview code(i used download listener too but not working).
I believe the Android default browser can't download .zip files by default (you should get a "This content is not supported" error).
If you want to download certain files through your own application though, you can try this this solution.
What code do you use? Could you specify it? I suggest you downloading it in AsyncTask via HTTP. Where do you save it? What is the error log? So many questions =)

Categories

Resources