How to call phone number with respective name in android - android

Trying to call number with name.It is possible to make name with number calling.
I successfully calling following code:
Intent callIntentp2 = new Intent(Intent.ACTION_CALL);
callIntentp2.setData(Uri.parse("tel: 55555555");
startActivity(callIntentp2);
It's Output looks like
55555555 Dialing
But I want to call with name just like you saved on contact list on your sim.but i have data in manually not from sim.
John 55555555 Dialing
Is that possible.

ACTION_CALL is a native Android intent. When you call it, Android performs background processes that bring up the default call view. There are ways you could chop together some broadcast receiver to overlay an activity on top of the native call screen, but you are asking for trouble on that end. Without a rooted device, this is a difficult process. This question is actually very similar to:
Replace native outgoing call Screen by custom screen android
I haven't read through the link or anything, but I am pretty sure they are going to say the same thing. Without doing some weird, iffy work-around you aren't likely to achieve this.
You could (theoretically) take the time prior to calling to add the number with the attached name to your contacts list. When the call is made, it will show the name and the number (since the name is listed as a contact and that is Android's default action). Once the call is done you could delete the contact so that it doesn't get stuck in a persons contact list that doesn't want it.
A bit of code for example:
ContentValues contactValues = new ContentValues();
contactValues.put(Data.RAW_CONTACT_ID, 001);
contactValues.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
contactValues.put(Phone.NUMBER, "555-555-5555");
contactValues.put(Phone.TYPE, Phone.TYPE_CUSTOM);
contactValues.put(Phone.LABEL, "John");
Uri dataUri = getContentResolver().insert(
android.provider.ContactsContract.Data.CONTENT_URI, contactValues);
Don't forget to add write contact permission to your applications manifest. Again, this is just an option (the only one I can really think of off the top of my head)

Related

How to obtain Skype ID from Contact DB on Android (my solution is almost OK)

EDIT
FYI, The trick which consists in extracting RawContactID from lookupKey (similar to "1450iSkype_288") does not work anymore.
Summary
I am able to obtain 'Skype ID' / 'Skype user name' , but my solution does not always work because it seems the contact DB of the Skype app does not always contain (expose?) 'all' the data.
Let me explain the situation before asking my question:
1 - Gathering info from Skype apk
Skype App (apk) contains /res/xml/contacts.xml which contains
<ContactsDataKind
android:icon="#ref/0x7f0e0004"
android:mimeType="vnd.android.cursor.item/com.skype4life.audio"
android:summaryColumn="data3"
android:detailColumn="data4" />
<ContactsDataKind
android:icon="#ref/0x7f0e0004"
android:mimeType="vnd.android.cursor.item/com.skype4life.video"
android:summaryColumn="data3"
android:detailColumn="data4" />
<ContactsDataKind
android:icon="#ref/0x7f0e0004"
android:mimeType="vnd.android.cursor.item/com.skype4life.message"
android:summaryColumn="data3"
android:detailColumn="data4" />
<ContactsDataKind
android:icon="#ref/0x7f0e0004"
android:mimeType="vnd.android.cursor.item/com.skype4life.phone"
android:summaryColumn="data3"
android:detailColumn="data4" />
The important data here is these 4 Skype mimeTypes:
"vnd.android.cursor.item/com.skype4life.phone"
"vnd.android.cursor.item/com.skype4life.message"
"vnd.android.cursor.item/com.skype4life.audio"
"vnd.android.cursor.item/com.skype4life.video"
Note:
It looks like these have been added around Augustus 2018 (see here http://www.skaip.org/skype-8-27-0-88-for-android )
One more usefull info is that the ContactsContract.RawContacts.ACCOUNT_TYPE of Skype is "com.skype.raider"
2 - Querying Content provider
Using info obtained in point 1, I could query the Skype ContentProvider (using selection ContactsContract.Data.MIMETYPE+ "= ? " and selectionArgs "com.skype.raider" ) and obtain data which must be 'interpreted' according to the mimeType (one of the 4 Skype mimeTypes obtained in point 1).
2.1 - For mimeType vnd.android.cursor.item/com.skype4life.message, I obtain something like this:
mimetype = vnd.android.cursor.item/com.skype4life.message
_id = 2773
lookup = 1450iSkype_288
contact_id = 1601
display_name = <Skype User DISPLAY Name HERE>
raw_contact_id = 515
mimetype = vnd.android.cursor.item/com.skype4life.message
data1 = 8:<skype.user.name.value.here>
data2 = null
data3 = Skype
is_primary = 0
data5 = null
Where
<Skype User DISPLAY Name HERE> is an actual Display Name
<skype.user.name.value.here> is an actual Skype user name / Skype ID
<skype.user.name.value.here> is the data I want, so this is good!
Important note:
EDIT: this trick does not work anymore ->
The lookup = 1450iSkype_288 can be parsed to obtain 288 which is the RawcontactId of some other contact!
If this rawContact has a contactId, then this allows me to find the original Contact (vs RawContact)
It does even sometimes refer some contact which is NOT a Google contact, but, for example, a WhatsApp contact!
Enjoy this important info ;-)
<- this trick does not work anymore
2.2 - Similar data for theses 2 mimeTypes:
"vnd.android.cursor.item/com.skype4life.audio"
"vnd.android.cursor.item/com.skype4life.video"
So I am also able to obtain <skype.user.name.value.here>. Again, this is good!
2.3 - the Phone mimeType
"vnd.android.cursor.item/com.skype4life.phone"
does not contain Skype ID (in field data1), but instead the phone number, which makes sense.
3 - The Problem
So, all this works fine an I decided to test my code on some other devices, where I installed Skype and used it with same Skype account + same Google account and, BOOM, here is the problem:
The Skype Content Provider only has data for mimeType
"vnd.android.cursor.item/com.skype4life.phone" // <- contains Skype user's phone number, NOT Skype user name / Skype ID
and has NO data for these 3 mimeTypes
"vnd.android.cursor.item/com.skype4life.message" // <- contains Skype username / ID
"vnd.android.cursor.item/com.skype4life.audio" // <- contains Skype username / ID
"vnd.android.cursor.item/com.skype4life.video" // <- contains Skype username / ID
Skype Phone Numbers are only usefull to pass phone call using Skype, but that's not what I want to do: I want to pass 'Internet Skype audio / video' calls, not 'regular cell phone' calls.
4 - Question
Why is the Skype app sometimes storing all 4 'phone/message/audio/video' mimeTypes data and sometimes, only 'phone' mimeType?
In the latter case, I am not able to obtain Skype Ids / Skype user names, i.e. the <skype.user.name.value.here> I mentioned above.
I understand my solution is the result of some kind of 'reverse-engineering-like method' and is not 'official' at all, but maybe someone else did the same kind of investigation I did and could find a solution?
Maybe there is some 'Skype sync settings' which should be activated within the Skype app or Within Android?
I already force contacts re-sync for Google and Skype accounts, but this did not help.
Thanks for your help.
What a great research! I got here because I stumbled upon the same problem. I also want to get skype username, but only mimetype "vnd.android.cursor.item/com.skype4life.phone" is present in the address book.
If I look at your link, where you mention these com.skype4life.* are added, I also see the addition of:
sync_adapter_account_type:
= com.skype4life
sync_adapter_authority:
= com.android.contacts
So they added this together. Maybe we should sync it in one way or another?
The mere problem is, that you don't have com.skype.raider.permission.ACCOUNT.
So you can only query them through ContentProvider or build an index to look them up.
For example:
How to get Skype info from the Android contact list?
Get Skype name from Contacts list
Intent strings alike com.skype.android.skypecall.action might not exist anymore, because com.skype.raider/com.skype4life obviously is not the same application.

Programming in Android Studio to able the user to give three numbers and save them

in android stuido I would like to code an activity, where the user can input numbers. For, example he types the number to the textfield, click 'OK' button, then the textfield gets clear, he types the second number, than the third, and after they give the third number the program goes to another activity and sayst thanks for the free number. I would like to save the three numbers for further use and have them in an ascending order. How should I do it?
I agree with Andrii, this is a very vague and general question. To get you pointed in the right direction though, you would want a layout with an number based-editText widget (for the user input). I would then add the button, and then implement OnClickListener for the button so that everytime the button is pressed, it calls a method you will define that will store the value in an array or list (which can be sorted), along with some kind of tracker to keep track of how many numbers have been entered - then clearing the editText field so that another number can be input; on the third number, the method calls the activity via intent or some other way saying "thanks for the free number".
This is all general and it is going to take quite a bit of work and API Guide/DeveloperDocs searching on the Android web site.

How to dynamically modify callers name

Is there a way how to dynamically modify the name that appears on the screen when somebody is calling?
For instance, I have a number "123456789" in my contact list under the name "Bill Gates". Now when the number "123456789" calls me, I want the corresponding name that appears on the screen to be changed to for instance "Test".
I have a broadcast receiver that is listening to incoming calls. Once I get the call with particular number (123456789), I change the contact name to the corresponding value (Test).
The contact name gets changed to "Test", however the name visible on the screen during the phone call does not change.
Isn't there something like an observer pattern where all the receivers get notified once the contact has been updated?
I tried contentResolver.notifyChange(URI_CONTACTS, null, true), however does not work
Thank you in advance for any suggestions
Is there a way how to dynamically modify the name that appears on the screen when somebody is calling?
No, at least no universal method which fits your scenario. The phone app would have to check for changes of the caller name by itself. As your test shows this does not apply to the phone app you are using.
Isn't there something like an observer pattern where all the receivers get notified once the contact has been updated?
Still, the phone app would have to register itself as an observer.

Android create contact problem

Hi
I wan to create a contact, so here is my code:
Intent addPersonIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
addPersonIntent.putExtra(Insert.NAME, "asd");
addPersonIntent.setType(Contacts.People.NAME);
addPersonIntent.putExtra(Insert.PHONE_TYPE, Contacts.Phones.TYPE_WORK);
addPersonIntent.putExtra(Insert.PHONE, Uri.decode("123"));
addPersonIntent.putExtra(Insert.PHONE_TYPE, Contacts.Phones.TYPE_MOBILE);
addPersonIntent.putExtra(Insert.PHONE, Uri.decode("123"));
addPersonIntent.setType(Contacts.Phones.CONTENT_ITEM_TYPE);
...
startActivity(addPersonIntent);
Why the only thing that is created is the mobile number, I never got the "work" number?
You're thinking of "putExtra" as adding to the end of an array - Your problem will be clearer if you think of it as setting name/value pairs in a hashtable. Basically, you're setting PHONE_TYPE to "work", PHONE to 123, PHONE_TYPE to "mobile" (overwriting when it was set to work), and PHONE to "123" again.
What you want to do is set either the "mobile" or "work" phone data using SECONDARY_PHONE and SECONDARY_PHONE_TYPE - Details here.
Also, keep in mind that all this follows the old version of the Contacts API, which is deprecated as of Android 2.0+. There's a handy resource on migrating your code to use the new contacts API here.
here is the next problem, when I add:
addPersonIntent.putExtra(Insert.NOTES, "asdkjhaskh");
the note data never appears in the activity, why?
The whole idea is to start the EditContactActivity.java with loaded data and for now I loaded phones, names and companies. For some reason I cant load notes, and another problem is how to set in the intent information for the IM? For example I tryed with:
addPersonIntent.putExtra(Insert.IM_HANDLE, "mySkype");
addPersonIntent.putExtra(Insert.IM_PROTOCOL, Uri.decode("skype"));
but it is not working.

how to get the localized label of the phone types?

When changing the custom locale the label of the phone types change to the appropriate language. Does anybody know how to get the localized label of the phone types?
I pick a contact in my app to get its phone number and if there is more then one number I use an AlertDialog to let the user select the currect one. In this pick list, I want to show the label of the type, so it's easier for the user to select. Since they labels are somewhere in the Android system, it must be possible to get the localized label. Unfortunately, the Phone.LABEL is null when reading the phone number.
I know this is a bit old, but this:
Phone.getTypeLabel(this.getResources(), cursor.getInt(typeIdx), "");
worked for me
Yes, you can get localized phone type string with the code:
int phoneNumberType = (int)pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
ContactsContract.CommonDataKinds.Phone.getTypeLabel(context.getResources(), phoneNumberType , "")
but for custom phone types you should cosider phone label, not only phone type:
String phoneLabel = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL));
Inferno's answer is a valid answer, and I was happy to find this answer because it was similar to what I was looking for. However, if you're dealing with phones installed with API Level 5 (Android 2.0) or newer, there is one small problem with this: android.R.array.phoneTypes only returns the list of phone types that were present prior to when ContactsContract class replaced the Contacts interface as of API Level 5. I verified the labels listed when creating a new contact on emulators running these Android versions (API Levels): 1.6 (4), 2.1-update 1 (7), and 2.2 (8).
When printed out, android.R.array.phoneTypes contains these valid phone types:
Home, Mobile, Work, Work Fax, Home Fax, Pager, Other, Custom
These are the valid phone types, present for phones with Android 2.0+ installed, that are missing from that same Array:
Callback, Car, Company Main, ISDN, Main, Other Fax, Radio, Telex, TTY TDD, Work Mobile, Work Pager, Assistant, MMS
Unfortunately, I have not been able to find something like android.R.array.phoneTypes that'll list all of these valid phone types for phones Android 2.0+. Has anyone come across such yet?
References
android.R.array.phoneTypes defined: http://developer.android.com/reference/android/R.array.html#phoneTypes
Note: I'm posting my other two reference links in separate answers, as I can't seem to post more than one hyperlink per post at this time.
i am using this piece of code
public void getPhoneType(){
int res;
for(int i=0;i<=20;i++){
res = ContactsContract.CommonDataKinds.Phone.getTypeLabelResource(i);
Log.d(TAG,"i: "+ i +" type: " + context.getString(res));
}
}
didn't found any place to get the actual count of valid types but http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html#getTypeLabelResource%28int%29 says it will always give a valid res so, you can iterate until it start giving repeated values... to me after 20 gives me the custom res.

Categories

Resources