avrazor
avrazor

Reputation: 21

Running HTML5 with Database in Android WebView

I am developing an app with html5 pages locally stored in the assets folder. I have included a database with some php scripts, is it still possible to run in WebView?

Upvotes: 1

Views: 1355

Answers (2)

MHP
MHP

Reputation: 2731

for using database in webView you have two ways:

1) use localStorage that you should handle it by javaScript

2) use java database,for that you need javaScriptInterFace() that provide you a bridge between javaScript and java class. and create java database then put your data in it or read from it

see this link it will help you-(this link show you how use java database like browser localStorage)

Upvotes: 2

Vivo
Vivo

Reputation: 768

No not at all you can not run a php in a webview it can understand only html ,CSS and JavaScript just like a browser.

Suggestion 1:

If you want to build a HTML page using your local database you could do that using java no need of php.

Just fetch the data from db then build HTML page by concatenating java strings with the data,HTML mark up,CSS and javascript then load the resulting HTML page in webview

If you want to access Java function from JavaScript you could use addjavascriptinterface of java.

The java function can be anything like a function that inserts or updates data into local dB or a function that returns a data from local db

It can also produce dynamic html content locally jus like a dynamic web language like php,classic asp etc..

Suggestion 2:

If you want to do it using php then you have to host it in the internet server along with db and load the page URL in webview

Upvotes: 0

Related Questions