Get email extra from new outgoing call intent - android

I'm writing a BroadcastReceiver that responds to the NEW_OUTGOING_CALL action. Meaning, every time the user makes a new phone call - my BroadcastReceiver is called.
I want to get the email of the contact the user is calling.
Here are the extras I can get from the intent:
Bundle[{android.phone.extra.ALREADY_CALLED=false, android.intent.extra.PHONE_NUMBER=123, android.phone.extra.ORIGINAL_URI=tel:123}]
Any ideas? Thanks.

You may want to have a look at the Contacts API which allows you to look up various contact informations in different ways. And then maybe go via the PhoneLookup table to quickly find a contact id for a phone number.
If you haven't used the Contacts API be prepared to learn some 'interesting' approaches and bear in mind that, more and less behind the scenes, it's all only about building select statements for DB tables. - But see for yourself: Using contacts API.

Related

Invoke Calling from Fulfilment Webhook response

I have a contact app, I created an Action Project which eventually decide a number to call based on user conversation. The number to call is being decided at backend (Fullfilment using Webhook).
I want to start call on number being decided at backend(As it is when you say 'Call 55555555' in Google Assistant).
I am not able to find any document on how to start a call using response from Fullfilment.
Please suggest.
You cannot programmatically start a phone call with Actions on Google.

Obtaining Telephone Number from a Call at a Specific Moment in Time

New to Android development and I’d like to very quickly check if the user is in a call AND get the phone number of the person the user is in a call with. In reviewing https://developer.android.com/reference/android/telephony/package-summary, it appears quickly grabbing this phone number is not possible. It appears the only time the number is available is with a PhoneStateListener and onCallStateChanged during an actual “state change” or using a BroadcastReceiver with state changes and grabbing EXTRA_INCOMING_NUMBER or related when a change occurs. Am I missing anything?
Thank you.
you're not missing anything, that's the way to do it.

Why do we need a UserHandle in many API declarations

In Android Open Source Project, a lot of core API declarations have an integer parameter userId in the end. I traced back and figured out the integer comes from a class called "UserHandle.java". There is a simple comments saying this class represents a user on the device. It still confuses me. Why do we need such a class? What's the difference between different values of the class, such as "USER_OWNER", "USER_CURRENT", "USER_CURRENT_OR_SELF"?
Thanks in advance!!!
Ever since Jelly Bean, Android platform has supported multiple users. This means that multiple users may be able to use one device, yet not be able to access other user's files or communicate with another user's app.
The first user on the device is user 0. The rest start their numbering from 10,11,... (In JB the numbering was 1,2...).
USER_OWNER is user 0.
He has some extra privileges over the other users (mostly access certain settings that others can't or uninstall an app for all users).
Multiple users on one device requires that only one user can be active in a specific point in time, this user is referred to as USER_CURRENT (since Kitkat().
In general one user's application can't send a broadcast message or an Intent to other user's apps.
Only apps with system permissions can do that (for example when the battery is running low, an intent will be sent to all).
Whenever you send an Intent from your app, the system service verifies whether this is a valid Intent i.e. if its supposed to reach all users then it's not.
This means that even if you were to use a certain api with the wrong userId (for example you force userId=0 even though this is user 10), then your call will receive a SecurityException.
To avoid such exceptions, there is also the option to send an Intent with USER_CURRENT_OR_SELF.
This means you're trying to send to the current user, but if he's not allowed to receive the Intent, let the same user who sent the Intent receive it.

Intent resolution in Android

If I want to create custom address book (which overrides my phone's default address book), and if I want it to be used by all applications, what should be my intent-filter? Does Android allow me to do such a thing considering the fact that such a third-party app could potentially be malicious?!
And, if I want to have yet another address book application, I suppose the second app also has same intent-filter, isn't it? How does the framework decide which app to pick if I click on Contacts button when making a call? In other words, how does the framework resolve intents in case,there is a conflict between multiple intent-filters?
You can replace any application on Android platform, even Home. Android documentation explains everything there is to know about Intents and Intent Filters and there is a section called Intent Resolution that answers your question. Intent Resolution section for Intent class has some additional information.
As far as I can tell Android doesn't try to resolve a conflict. It ask the user which application to run and gives them the choice to mark this Activity as the default for this Intent. They give an example about mail app here.
While Mr. Smiljanić is basically correct, there is no Contacts application in Android for you to replace. There is Dialtacts, which is the application supporting the contacts, call log, and dialer. That application cannot be replaced, mostly because the dialer cannot be replaced.
So, while you may be able to override some intent filters and get control on some contacts-related requests, you will be unable to get the contacts portion of Dialtacts overridden, which will confuse users.

How to start an ACTION_PICK activity with only those contacts which have a mobile phone

I want the user to select a contact to which my application would send a SMS. How do I ensure that when I start an activity with ACTION_PICK intent only those contacts with mobile phone numbers are displayed?
Currently, I'm starting the activity like this:
Intent intent = new Intent(Intent.ACTION_PICK, Phones.CONTENT_URI);
You can use:
intent.setType(android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
However when used the contact picker will display a list of all the phone numbers with the contacts name above each one so if a contact has multiple numbers you will see multiple entries for that contact
I suspect it is not possible. You would need a separate Uri, one that the Phones content provider used to restrict the output to mobile phones only. I do not see that such a Uri exists.
You can still have an activity pick only users with phone numbers, but you will have to write the activity yourself, using a managedQuery().
Reading the code, it looks like you can specify the UI.LIST_CONTACTS_WITH_PHONES_ACTION action in the intent to show only contacts with phone numbers. I haven't tried this out though. Also, this action has the same effect as the contact setting "Only contacts with phones"

Categories

Resources