I am creating an app to backup contacts to a webserver. I am still new to android development so I can't think of the logic to do this. I know that the contact id is not constant and it can change. So how can I keep track of changed data to existing and new contacts?
You need to first grab the contacts in Android look at the example code in the AOSP project for the people app, that will show you the way that Google is doing it officially, which doesn't necessarily make it the best method, but it's a lot easier to re-tool their code than write it all from scratch.
Here's how to get started with the Android build environment:
http://source.android.com/source/initializing.html
Here's another question, similar to yours that might help with the contact data:
How to read contacts on Android 2.0
On your end, you need to setup a SQL server of some kind... and one of the fields just needs to be "Last Updated", either add a date to that field, or a revision number that you're tracking elsewhere and decide to update based on the query out of that field.
Related
I have a situation where admin has defined both English and Spanish Language at the admin panel. Right now, Whatever the changes he made in admin panel, it is reflecting on the website.
My question that when we have different platforms like Android and iOS, Whatever the changes he made in the Admin panel I want it to reflect in the Android as well. As of now, I have defined both language information in Strings.xml.
I do not think calling server each time for the Labels is a good idea. If i do, it might slow down the app.
In detail, i have a validation message like "Please Enter User Name". And the admin changed the label in the back-end and made it Enter User Name. Each time calling server to get the information is bad idea. I would like to save the information or data for certain periods. say 2 hours or 24 hours.
What is the best way to achieve this?
In my opinion the best solution is to keep it in sqlite. You should check version of strings by calling your API when i.e. application is starting and then update its if necessary.
Unfortunatell queries SQLITE every time when user open new activity/fragment might also slow down your app. In my opinion you should keep your map of string in Application Class or in Object (if you use kotlin) - query your sqlite after checking version of your string or when app is starting if API is unavailable.
I want to make an android quiz app that I can update on daily basis.Like update daily General knowledge question answers .New section of question set date vice . I am just a beginner in android and need some guidance . So please guide and give some reference that I can use .
You can use Parse.com for such purpose.
Here is link for parse.com for documentation link for parse.com usage example take start from this site link last but not least do follow official android docs link
As you are saying you are new to Android so keep it simple just make the app to fetch the data from server. The other way is to store the data in SQlite and make your app run offline also.
As you have asked I can update on daily basis
So if you want to updates the question then you can do that from your server itself but if you want to update your app then you need to make your app in generalized manner thinking of your future updates, so that you can easily integrate the future functionalities whenever you needed.
for starters, keep the code and data separate, so you can trigger a fetch from a webserver (in XML or whatever format) with the day's quiz data, then parse and display it from your program. and cache it in a text file so you have something to use in case there is no web connection; nobody likes an app that just hangs.
In my app a user can (only) see the values uploaded by admin.
For example. A salesman is using the app will be able to see the latest rate provided by the manger to trade.
Now the question is "where to put these values?"
I have .net webservice experience with android but I guess it wont work in this scenario,will it?
Any suggestion that the returned result be in (preferably) XML format.
It sounds like you already know how to do this. You can download and parse xml within your app. If you alreayd know how to set up the websever, the rest is easy. Limiting who can see what is just a matter of associating specific transactions with an individuals account. Then just have the phone check for updates on that transaction when the app loads (using someting like AsyncTask) or if you want to get more complicated you could push notificatinos using the android cloud service, or even use a REST model. More details are needed for a more specific answer but you can do what you want.
You can do it on your own, and build a webserver with a MySQL/PHP JSON API or you can use parse.com for a smaller project.
I have a few questions about the concept of androids timestamps. I want to synchronize my contacts but only if the timestamp of the contacts detail in the android is older than that one in my database.
My questions. Is there a timestamp for each detail like phonenumer, emailaddress and address. And who to check it? I tried it for ContactsContract.CommonDataKinds.Phone.STATUS_TIMESTAMP which is always null.
Any ideas? The Android Api tells me that there should be a timestamp (long).
Thanksfor your help.
There isn't. The field you're talking about is a convenience for someone who wants to stamp the row with the last time the raw contact's status was updated. I doubt that the Android system itself is using it.
I think that Contacts synchronization assumes that Google Contacts is the source of all knowledge, and the Android system is just a reflection of it. If something changes on Android, and it hasn't changed in Google Contacts, then it gets uploaded to Google Contacts. Changes on Google Contacts overwrite anything on Android.
On the whole, I'm suspicious of synchronization based on timestamps, because it has a tendency to get screwed up.
Are you trying to replace the google.com sync adapter with your own? You're a brave person!
CONTACT_LAST_UPDATED_TIMESTAMP
is added in the API 18. The same can be used.
I'm trying to do a sync adapter to sync my contacts with an webstorage.
When I ask this server for any contactupdates on the server-side I get a list of all the new informations added/changed. To update them I'm using the preferred method described here
My problem is that when I make a ContactOperations.newUpdate() and feed it with all the new/changed informations I got from the webserver and then apply it to the ContactsContract.AUTHORITY all the informations already stored on the phone are erased?!?
I make an example to make thinks clear:
I have an contact saved on my phone named: John 'Dady' Doe. Now the SyncAdapter ist invoked by the system, he ask the server for any contactchanges and the server says, that the familyname of this contact now is "Jones". With that information I construct a new ContactProviderOperation.newUpdate() and feed it via .withValue() and apply it. But what Android really does is: It flushes all othere columns and now my contact is named "Jones" (givenName and middleName missing -.-).
Is there any way to prevent Android from doing so? Can I pass any parameter like the CALLER_IS_SYNCADAPTER? Or do I need to make my own workaround (hopefully not), like reading the data record first, apply the updates and then apply it to the ContactsContract.AUTHORITY?
Any hint is really appreciated!
/edit: I did further studies by looking at the SyncAdapterExample, especially at the "update a contact"-part, but what I saw kinda shocked me: Google actually does read the contact first, then apply the updates from the server and reapply it to the ContactsContract.AUTHORITY. But they only handle first- and lastname, one email and two phones (normal and mobile). In my case I wan't to handle ALL contactinformations, so it's not feasible to do such a workaround, except there is no other way, which I hope not. Hopefully someone can head me in the right direction for this.
Totally my fault :/
Android is doing everything right, I just failed as hard as this guy ...