Android Question Example writing to database via JSON

MikeFree

Member
Hello all,

i switched to B4A because it seams be easier to create Android apps in this way.

I created long ago a demo example with Android studio. Login procedure and register procedure by using JSON package.
Writing data to an local database on the phone database.

My question is a similar example available for B4A?

I attached some plain android java code for better understanding what i mean. The hole project ist to large for uploading here.

the login procedure of the app works like this youtube tutorial :


thanks for your tipps.

Friendly regards
 

Attachments

  • Sourses_MySqlDbDemo.zip
    4 KB · Views: 189
  • prg.zip
    33 KB · Views: 195

KMatle

Expert
Licensed User
Longtime User
B4x supports anything you can imagine (db's and JSON are just basics). You can search the forum (not because I'm too lazy to explain but we have tons of examples here as you're not the first one asking those questions). For a local db it's a good option to search for SQLite. Very easy and just some lines of code and a checkmark on the corresponding library.

ONE of the SQLite examples handling millions of rows like if it's nothing: https://www.b4x.com/android/forum/threads/b4x-sqlite-with-6-million-rows.91563/ (it's for B4J but the code is the same). Basics of SQLite: https://www.b4x.com/android/forum/threads/sqlitelight-four-simple-sqlite-projects.35419/#content

JSON: https://www.b4x.com/android/forum/threads/android-json-tutorial.6923/
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Here is one of the examples

If you want to store the data to local sqlite database, check the SQL tutorial.
 
Upvote 0

MikeFree

Member

your app is running but i get message ".. account is not activated"
I tried to run with a local appache server ... but api is not running.

can you explain where to set the api-folder within appache server?
on the other hand i cannot see that you use JSON data to manage login or register user?
For security issuse i learned to transfer data using JSON
 

Attachments

  • 2020-06-07 21_02_23-test_remote_Server.jpg
    27 KB · Views: 150
  • 2020-06-07 21_02_23-test_remote_Server_02.jpg
    24.4 KB · Views: 195
  • 2020-06-07 21_02_23-test_remote_Server_03.jpg
    16.2 KB · Views: 153
Upvote 0

aeric

Expert
Licensed User
Longtime User
your app is running but i get message ".. account is not activated"
This mean you need to click on the activation link to activate your account. Otherwise, you can change the value from backend.
Open "tbl_users" table and change the value for "user_activation_flag" from "M" to "R" and you can proceed to login.

can you explain where to set the api-folder within appache server?
You should put your folder inside htdocs folder. Assume your web server is running port 80, then you can browse to http://localhost/api in your browser.

on the other hand i cannot see that you use JSON data to manage login or register user?
I am indeed using JSON format to transfer data. I use JSON Parser and JSON Generator in B4A and json_encode / json_decode in PHP.
B4X:
Dim Map2 As Map
Map2.Initialize
Map2.Put("eml", strUserEmail)
Map2.Put("pwd", strUserPassword)
jsn = Routine.Map2Json(Map2)
job.Initialize("", Me)
job.PostString(Starter.strURL & "user/login", jsn)
Wait For (job) JobDone(job As HttpJob)
ProgressDialogHide
If job.Success Then
    strData = job.GetString
    job.Release
Please start a new thread about question related to my thread. Thanks.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Another mistake you made is strURL should not point to IP with port 3306. Port 3306 is default port for MySQL. By default, apache web server is using port 80. In my case I change to port 8000 because my port 80 is already used by IIS.
 
Upvote 0

MikeFree

Member
 

Attachments

  • 2020_06_14_19.20.41.jpg
    266.5 KB · Views: 177
  • 2020-06-14 19_44_50-Servererror.jpg
    44.4 KB · Views: 153
Upvote 0

aeric

Expert
Licensed User
Longtime User
it try to find .. but did not find where Address admin@localhost is build ... seams thet php skript generates the mail adress?
I am not sure if you use xampp server for local development but if you use Laragon, you may able to "catch" the email as text file. If you are uploading the folder to a production web hosting, make sure to use a valid email address to send and receive email.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…