Get Top Contacted data in android - android

I am trying to get the top contacted call log details in android. Say if the person A has been contacted for 5 times, B has been contacted for 3 times and C 10 times. Now, I want to extract C and A as my top contacted persons in my phone.
Can any body explain me how to do this. I am able to get most recent call logs now.
I referred this, but no luck
How to get contacts with which the user talks often?

I was able to do something similar in a different approach. In the Contacts API, there is a field called ContactsContract.Contacts.TIMES_CONTACTED which tells the number of times that contact has been contacted.
This approach is not related to the CallLogs API. User can clear the CallLogs, but not the times contacted.
Check this link for developer notes on ContactsContract.Contacts.
Check this link for an android library that I have created which can give you this implementation.ae-apps-library You would be looking for the class ContactManager. Once you fetch all the contacts, you need to sort based on the times contacted field to get your required list.
Edit: If you see the fetchAllContacts method in the ContactManager from the library, you can see how the data are read using the API. All you need to do would be to sort this list based on the timesContacted field by writing a Custom Comparator and sorting the list using that.

Related

How to get full information about "other contacts" using People API?

Background
I work on an app that needs to get information of "other contacts" as they appear on the address book page on "Contacts" website of Google:
The problem
The Contacts API is becoming deprecated, and instead we need to use People API.
For this, I use the Java library (here) which makes it easier to reach the various functions.
Sadly, according to the docs (here), querying the list of items from "other contacts" you will get only up to 3 possible fields:
emailAddresses
names
phoneNumbers
Indeed, when using it, that's what I got. I also got fields of "etag" and "resourceName", but that's it. No photos, no cover photos, no nothing else...
The code to do it is very short (after you set everything up) :
val otherContactsResponse =
otherContacts.list().setReadMask("emailAddresses,names,phoneNumbers")
.setPageSize(itemsCountToRequest).setPageToken(nextPageToken).execute()
val result=otherContactsResponse.otherContacts
What I've tried
I tried to see if I can query by "reourceName" (example this one), but it seems that "other contacts" are handled differently than normal ones, so this won't work:
result.forEach { personBasic: Person ->
val test: Person? = peopleService.get(personBasic.resourceName!!)
.setPersonFields(
"addresses,ageRanges,birthdays,coverPhotos,emailAddresses,genders,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,urls")
.execute()
Log.d("AppLog", "$test")
}
Sadly there is no similar query for "other contacts" part to search (other than here, which gives you again the same 3 fields).
Tried to find if there are other fields that I missed that could be used somewhere else. I don't even know if resourceName or etag are reliable and unique for querying.
Tried to add more fields to the query, despite the docs talking about just 3 fields. Failed, of course...
There is a function called copyOtherContactToMyContactsGroup (here) which seems that it will copy contacts to the main group of contacts. I guess that if I use this and then query the contacts themselves (not just "other contacts"), I could get the needed information. But this is a waste of time and can pollute the user's address book, even temporarily. I would have to make sure I delete the contacts from there right after I add them...
EDIT: tried this too, and while it seems to work, I don't want to use it as it pollutes the address book with contacts that the users hasn't added. Plus I got sometimes an image which is simply the letter of the person with a background. This is the code of it:
result.firstOrNull { !it.names.isNullOrEmpty()&&!it.emailAddresses.isNullOrEmpty() }?.let { person ->
val request =
CopyOtherContactToMyContactsGroupRequest().setCopyMask(
"emailAddresses,names,phoneNumbers")
.setReadMask(
"addresses,ageRanges,birthdays,coverPhotos,emailAddresses,genders,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,urls")
val copyResult: Person? =
services!!.otherContacts.copyOtherContactToMyContactsGroup(
person.resourceName, request).execute()
Log.d("AppLog", "success $copyResult")
}
Also, this seems to be extremely slow compared to simple queries, and there is no batch operation for it either. In addition, testing it out, I think it can cause various server issues related to quota being reached (about 180 per minute or so).
I think that as the website shows the photos and can show you per-contact information, we should have this API too, no?
I thought that maybe I could create a new group (label) , copy the "other contacts" to there, and then fetch the information from there (as it allows to get more fields), but the docs (here) say that it was possible before, and not anymore:
The only system contact groups that can have members added are contactGroups/myContacts and contactGroups/starred. Other system contact groups are deprecated and can only have contacts removed.
This is a bit better solution (if it worked) as I can remove groups safely without affecting actual contacts.
The question
What's the best way that I should use in order to get all kinds of information (like normal contacts) about each item in the "other contacts" list? Is it possible without copying to the contacts list and without getting "fake" photos (of the contact initial letter) ?
OK so sadly for now I got a workaround.
First I copy the various fields to a new Person object, one for each of the results of the query, then I add them all using a batchCreateContacts (here, max items per batch is ), and then I deleted them all using batchDeleteContacts (here , max items per batch is 500)
Sadly this still pollutes the address book, but it's much faster than what I've found, and it's quite temporary too.
Weird things I've found :
API usage doesn't seem to show the exact same items as on the website. I know because I tried to find names and emails on the website that I've found from the API but it didn't show them. Even weirder: The count of items seems the same between them
Some items just have names, which is weird because: how did they get there?
"Other" contacts are different from "normal" contacts and have less information available, but why is this? I looked into this a little and found the following:
Save contact info when you interact with people
When you interact with people on Google products, you can automatically save their contact info, including names, email addresses, and phone numbers. When this setting is turned on, you'll keep the contact info for:
People you've shared something with, like a document in Drive
People who share content with you, like shared albums in Google Photos
People included in events or groups you're in
I think that these are the "other" contacts that become a sort of staging ground with minimal collected information.
I have also found that, on the Google Contacts web page that whenever I add information to an "other contact," the contact automatically disappears from the "other" section and appears with the regular contacts.
So, from the web interface, it looks like "other" contacts should only have the minimal information such as name, email address and phone numbers and should be promoted to the regular contact list if information is added/updated. This scenario will explain why "other" contacts are treated differently.
If you are seeing "other" contacts with more than the minimal information, maybe that is the problem.
Update: Well, it turns out that any "normal" contact can be hidden in the web interface and all the information is transferred with the contact to the "other contacts" list, so "other" contacts can have more than the minimal information.
This looks like an unintended state of affairs to me.

Function to find whether the number is contact list android

Hi everyone i'am currently developing an android game, it uses your phone number when you first use the game(it is for an identification of the user).
It is an social game at some time when the user requests it returns a list of people who are currently online(playing the game),as json array(there phone number,name,photo)and from the data received you need to filter it out and display in two list views. The filtering done by this method:
1)Each element from JSON data(each person)if there phone number is found in user's contact list then is displayed in the first listview
2)if the number is not found in users contact list it is displayed in second listview.
But my doubt is that if the JSON array returns details of 10 people, you need to check for this 10 people whether they are in user's contact list.And does this kind of a technique takes a lot of time and creates delay in the UI..?
If yes please suggest me some other method.
Also please tell me how can I check whether a number is in user's contact list(I make the users upload there number to server without any country code).
So please in the number finding method you need to end the checking one a number has been fully completed.(starting from the end.
eg : 8086934565 (no saved in database) +918086934565(no in contact list)
then we need to start from last so that
5==5 then continue
6==6 then continue
till any of the no (+918086934565 or 8086934565) ends without breaking any equivalent condition.
eg for numbers +918086934565 and 8086933365
checking from the last
5==5,6==6, 5!=3 there the equivalent condition goes wrong and hence it should get out from the loop with a flag ie the numbers are not equal.
Please write me the function to do this or tell me an alternative method.
Any help would be appreciable.
Thanks.
Ugh, that's painful to read...haha...You're suggesting using phone numbers to identify users in a multiplayer matchmaking scenario? That's taboo...If you return a JSON array of users phone numbers, names, and photos, your app will almost certainly be permanently banned from the market and possibly your entire account. That is about the biggest security risk that I can possibly think of, you might as well have a textfield where everybody types in their social security number and it posts it to craigslist. Basically any of your users could just repeatedly initiate games with people and get names photos and phone numbers of 10 random people at a time by capturing the plain text JSON data coming back. If I were you I'd look into the facebook sdk for authentication or Google Play Game Services for multiplayer matchmaking unless the core mechanics of your game rely on phone numbers specifically, in which case by it's very nature is just not going to fly with users. Asking someone to write you a function to do that is most likely never going to happen on stackoverflow. I'm not even going to get into the last part of the question...This has to be a troll attempt...lol

Getting the name info of unknown phone number

Let's say we have got a number.We want to send SMS to this number but in the message body we want the user name.ie. "dear name surname". I searched the internet but could not find any code sample.Is not it possible in android?
That's a big problem, is it not ?
Many a times we get calls from phone nos, not in our phone contact list. Those numbers come as unknown numbers. Sometimes the nos, come as masked as well.
So if you are to develop an app to unmask those, how will you get around it ?
Well the solution is you gotta make use of trap calling web sites .
What are trap calling web sites ?
These are web sites , which do a reverse look up of the no that you query and it gives you the name of that number holder.
For e.g, if you are a person in US, then you can make use of the WhoIsThisPhone web site to find out the name of the person calling you.
In case, it's a masked no, you can get around that one too . But you will have to you to pay a subscription fee on a monthly basis for availing this feature(services like trap call are available as apps itself ) .
Depending on which country you are in, you will have to make use of similar services/web sites available to get your job done .

Get full google contacts list using OAuth

I'm trying to receive the user contact list from gmail using this (http://androidwarzone.blogspot.com.br/2011/07/android-oauth-full-example-with-source.html) tutorial. Everything worked just great, but I'm just receiving 24 contacts, nothing more, nothing less. If i delete an contact that is receiving and try to get the list again, ir brings me another contact placing the deleted spot.
How do I get the full list? There is a better way instead of this tutorial?
All contacts, including gmail, can be queried directly from the contacts content provider on the device.
http://developer.android.com/guide/topics/providers/contacts-provider.html#Access
In the tutorial what u have mentioned, in C.java file, for GET_CONTACTS_FROM_GOOGLE_REQUEST use this url https://www.google.com/m8/feeds/contacts/default/full?max-results=1000&alt=json
Here max-results=1000 means maximum 1000 results to retrieve per request

Possibility of a custom Contacts field with a set list of values and Contacts lookup performance

I'm pretty sure it's not viable to do what I'd like to based on some initial research, but I figured it couldn't hurt to ask the community of experts here in case someone knows a way.
I'd like to create a custom field for contacts that the user is able to edit from the main Contacts app; however, the user should only be allowed to select from a list of four specific values. A short list of string values would be ideal, but an int with a min/max range would suffice.
I'm interested in knowing if it's possible either way, but also wondering if it make sense to go this route performance wise. More specifically, would it be better to look up a contact (based on a phone number) each time a call or SMS message is received or better to store my own set of data (consisting of name, numbers, and the custom field) and just syncing contact info in a thread every so often? Or syncing contacts the first time the app is run and then registering for changes using ContentObserver?
Here is a similar question with an answer that explains how to add a custom field to a contact.
Thanks in advance.
I don't see the purpose to have your own set of data against contacts stored in your separate database, as you obviously will run into sync issues. You can use the mimetype and store whatever you want against the contact, in the manner you linked.
Whenever you want to looup contacts you can do that by using your custom mimetype. You get the contact id (from ContactsContract.Data.CONTENT_URI), and then you run another query to get the contact details (from ContactsContract.Contacts.CONTENT_URI). Please note these are different tables.
I'd like to create a custom field for contacts that the user is able to edit from the main Contacts app
I don't see that possible, editable from the main app, when you use your custom mimetypes, and you don't have much options here. The main contact app will display only the fields that are in SDK. You can store details against contacts but they won't show up in the inbuilt edit contact screen.

Categories

Resources