0

I want the user to be able to send an sms by either dialing a phone number himself or picking it up from a contact list.

I know that I could easily achieve it, querying all the contacts and providing a TextView to either filtering the contacts or dialing a number but my question his aimed to simplify the code.

On the default lollipop Messenger app, if the user clicks the "+" plus button, he can do exactly what I've described before: here's a screenshot of what I mean.

On Android, there is a pretty similar function which I am able to reproduce using this code:

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(intent, 1);

However, it only let the user pick up an already existing contact and eventually extracts a phone number from it.

Shortly my question is: Is there any way to reproduce the default Messenger behavior by using Intents?

Thanks in advance.

Lampione
  • 1,622
  • 3
  • 21
  • 39
  • like this: https://codeshare.io/aFQT7 ? – pskink Aug 04 '15 at 04:46
  • @pskink thank you for the code, it helps. However this is actually what I'm trying to avoid but from what I see there is no native function to do so. Thank you. – Lampione Aug 04 '15 at 11:49
  • 1
    "but my question is aimed to simplify the code." what can be simpler than those 20 lines of code (i am not counting the first 8 lines that creates the UI) ? – pskink Aug 04 '15 at 12:08
  • Yes in fact I really appreciate the code. I was looking for a way to simply call an intent. I'm starting exactly from you code, but if you have a look at the screenshot I posted, there is much more to build from scratch at least talking about UI. – Lampione Aug 04 '15 at 12:15
  • so create an Activity for that, like any other choosers do, you would need to call `setResult()` before `finish()` that way you can `startActivityForResult()` – pskink Aug 04 '15 at 12:16

0 Answers0