Hi guys. This is the version 2 of the ContactsDemo app. I have made some improvements after everyone's experience with the previous app. I will highlight some of those changes here.
Checkout the new blog that explains the cogs in motion for the app:
Syncing Contacts with an Android Application
I have switched the programming language to Kotlin for this app. I hope this will make the code more concise and easy to read.
So this app works in tandem with a very simple node server. The server doesn't do much but maintains a list of numbers. This list is synced with the device's numbers via the SyncAdapter.
Those who do not want to setup a server may skip the Setup part. To work without a server, you simply have to modify the SyncAdapter file a bit and get the app running.
- Open SyncAdapter in your editor or IDE.
- Go to performSync() method.
- Uncomment region "Dummy response" and comment out region "Server response".
- Go to variable "dummyServerResponseList" and add the numbers you want to sync to the list.
- Go to getFormattedNumber() method and change it to suit your device's number formatting.
- That's it. Run the app and click on button "Refresh Contacts".
- If you want to add/remove a number just add/remove it from the list then run the app and click button "Refresh Contacts".
You will need to install nodejs and npm to run the server. Also you need mysql as the database.
- Install mysql from here
- Create a database in mysql.
- In your database, create a table named "numbers" with a column "number". "number" can be of type varchar(20).
- Update the app.js file in the demo_server folder to whatever your user, password and database is.
- Now install nodejs from here
Use command node to start the server on localhost:3000
cd demo_server
node app.js
In case the server does not start, just delete node_modules folder and run
npm install
Then launch the app
- Register number:
-
Click Refresh Contacts
-
Number registered:
- Deregister number:
-
Click Refresh Contacts
-
Number deregistered: