0

I did a HTML which includes values which are changed with javascript (after button pressed) and I did an android app with flutter. What is the best way to get this updated data from the HTML in my android app? I tried webview, but it seems not to work, I don't want to load the whole page, only some specific data from it. I tried with json parsing, but I didn't find any way to write my data as json, even if I write json values before (for testing) I can't get this data with this method in my app.

Part of my html:

<tr>
    <td><button id = "btnKli" onclick = "getTEST();">OFF</button></td>
    <td><p>TEST</p></td>
    <td><p id = "t_valKli">0</p></td>
    <td><p id = "t_totKli">0</p></td>
    <td><p id = "t_perKli">0</p></td>
</tr>

I need the changed values from t_valKli etc. This values are changed via javascript in a variable with different functions and t_valKli get changed as following:

document.getElementById("t_valKli").innerHTML = parseFloat(valKli).toFixed(2)

Thank you in advance.

I tried webview but it don't work (probably outdated OS, but I need AND 5.0). I tried html parser, but I only get the fixed values, not the changed one. I tried to write the values as json, but can only read full json files with flutters json parser. I tried to save the values in an extra json file, but it won't overwrite this files and create new ones.

  • I can not understand what you are trying to achieve. – rckrd Feb 18 '23 at 21:30
  • Well I have an android app and I need special values. This values are generated in a html with javascript and I want to get this data in my app. This html I run on a webserver with a raspberry pi. – MrShady187 Feb 18 '23 at 21:37
  • have look at this? https://docs.flutter.dev/cookbook/networking/fetch-data – rckrd Feb 18 '23 at 21:39
  • and this? https://medium.com/flutter-community/parsing-html-in-dart-with-html-package-cd43c29cc460 – rckrd Feb 18 '23 at 21:40
  • or this? https://stackoverflow.com/questions/62577610/how-can-i-parse-html-in-flutter – rckrd Feb 18 '23 at 21:41
  • Yes, this was my first intention, but this parse only json and it seems only to work if nothing else on the html is there. I tried for testing just to put json values before my begins and it don't work, if I remove anything and just let stay the json values there, it works. – MrShady187 Feb 18 '23 at 21:48
  • Yep, I literally was at this 2 last links of you, with both I have the problem that I can only get the values I wrote in my html but not when they were changed with javascript – MrShady187 Feb 18 '23 at 21:50
  • I change the values with javascript as following - document.getElementById("t_valKli").innerHTML = parseFloat(valKli).toFixed(2); - and valKli is a variable that get changed via different functions – MrShady187 Feb 18 '23 at 21:51
  • Again what are you trying to achieve ? Take a step back and explain your problem in a bigger context. – rckrd Feb 18 '23 at 21:54
  • Well this app should "simulate" an app for an electric vehicle and should tell me the power consumption of different systems. This power consumption values I generate randomly in a specific range for 8 different systems. On my html I can toggle buttons to ON/OFF to simulate this systems are running, they show actual consumption, total consumption and the percent related to the other systems.. All I need are this values -which are changed every second if the button is ON - in my android app. – MrShady187 Feb 18 '23 at 21:58
  • From wheree is your "html" originating ? – rckrd Feb 18 '23 at 22:00
  • I wrote this html by myself and it is running on my raspberry pi /var/www/html and this raspberry pi works as a webserver, so I can get this values from my android tablet via wifi – MrShady187 Feb 18 '23 at 22:02
  • Flutter is not HTML. – rckrd Feb 18 '23 at 22:04
  • Yeah I know, I wrote the app in dart language – MrShady187 Feb 18 '23 at 22:04
  • Ok great . You are saying "I need the changed values from t_valKli etc.". Is this in the Flutter app or the website on your rPI? – rckrd Feb 18 '23 at 22:12
  • This is all on my HTML, in my android app I created mostly the UI and like I said I coded the part that I can get the data from my webserver, but only as json.. – MrShady187 Feb 18 '23 at 22:26
  • Whats you objective ? – rckrd Feb 18 '23 at 22:27
  • Still do not get it. Whats the purpose of the app? – rckrd Feb 18 '23 at 22:28
  • Just getting this values.. Like I said this is something like a simulation for an app in an electric vehicle which would show the power consumption of different systems like heating or infotainment. – MrShady187 Feb 18 '23 at 22:31
  • It's not clear why you can't make the web server, that you control, send back JSON. – Dave Newton Feb 18 '23 at 22:55
  • Well what I tested is to write any json values before my html starts, just to test if my App can read it. If I have an html with following `{"Infotainment": 29}`my App can read it, if I have the same, following by my html, body, script and so on, my App can't read this value even if it's at the beginning of my html-file. So I thought this "json parser" can only handle "json code" without anything else in the file.. – MrShady187 Feb 18 '23 at 23:12
  • The API should return JSON, not JSON + whatever else. JSON APIs return JSON. The data used by an HTML page can come from the same source as where the JSON-only endpoint gets it from. – Dave Newton Feb 19 '23 at 16:22

0 Answers0