0
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
// intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);

I am working on an application that helps the user to share his/her any accessible item(file) in the device. Codes above help user to select file(s) in the device. It is perfect! But I also want to give an opportunity to users as sharing their contacts(full contact details) with others by using my app. I tried intent.putExtras() but it supported in Build.VERSION.SDK_INT >= 19 devices (my app's min SDK is 17). It seems contact pick action requires different kind of intent type rather than "*/*". So, how merge these types of intents together? What can I do to solve the problem?

p.s I added following line to the manifest:

<uses-permission android:name="android.permission.READ_CONTACTS"/>

Brandon Zamudio marked the question as possible duplicate of this question but I can explain why it is not. In original question Hardik Trivedi wanted to pick contacts using intent. But in my case I want to give some different options to user to select. So, my problem should not be same with the original question. I did not share some pieces of my codes, but it is different one. Thanks for attention.

Mirjalal
  • 1,292
  • 1
  • 17
  • 40
  • 1
    Um, `putExtra()` has been supported since API Level 1. "It seems contact pick action requires different kind of intent type rather than "*/*"" -- usually, you use `ACTION_PICK` and `ContactsContract.Contacts.CONTENT_URI`. "how merge these types of intents together?" -- generally, you don't. – CommonsWare Apr 24 '17 at 19:35
  • Thanks for your quick response. But I wrote `putExtras()` not `putExtra()`. If I understand clearly, `.... = new Intent(ACTION_PICK)` and `setType(ContactsContract.Contacts.CONTENT_URI)` could solve my problem? – Mirjalal Apr 24 '17 at 19:51
  • OK, sorry about that, though I fail to see what `putExtras()` has to do with your problem. `ContactsContract.Contacts.CONTENT_URI` is a `Uri`, not a MIME type. You would create the `Intent` via `new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)` or the equivalent. – CommonsWare Apr 24 '17 at 19:54
  • no problem, sir. :) give me a moment to try it. – Mirjalal Apr 24 '17 at 19:56
  • I tried as you said, but when clicked to 'Contacts' element, it ends intent and not opens the 'Contacts' app to pick a contact. – Mirjalal Apr 24 '17 at 20:13
  • Sorry, but I do not know what "clicked to 'Contacts' element" means. [Here is a sample app](https://github.com/commonsguy/cw-omnibus/tree/master/ConfigChange/Bundle) demonstrating how to pick a contact from the `ContactsContract` `ContentProvider`. – CommonsWare Apr 24 '17 at 20:27
  • It is my sorry, I could not explain my idea well. Umm, I analysed codes in sample app. It provides to select a contact, but in my app user should be able to choose contact or file. – Mirjalal Apr 24 '17 at 20:39
  • So, have two options in your UI: one to pick a contact, one to pick a piece of content (note: `ACTION_GET_CONTENT` has little to do with files). – CommonsWare Apr 24 '17 at 20:47
  • In UI I am not able to pick contact. When I choose it, intent ends and returns _unsuccessfulResultCode_. I could not understand what I am doing wrong but now I am planning to approach to the problem from _different angle_ :) – Mirjalal Apr 25 '17 at 04:36
  • Possible duplicate of [Pick contact directly from contact picker intent](https://stackoverflow.com/questions/41327416/pick-contact-directly-from-contact-picker-intent) – Brandon Zamudio May 22 '17 at 19:46
  • @BrandonZamudio I explained why my question is not duplicate of another one. – Mirjalal May 29 '17 at 12:07

1 Answers1

0

Actually, I wrote almost same codes approximately 2 years ago. In two days I searched for these lines. Fortunately I found them in my second Hello World! application. :)

Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // for Camera app

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE); // not necessary, but recommended

Intent contacts = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
contacts.setType(ContactsContract.Contacts.CONTENT_TYPE);

Intent chooserIntent = createChooser(intent, "Select item");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{ takePicture, contacts });

startActivityForResult(chooserIntent, CHOOSE_FILE_RESULT_CODE);
Mirjalal
  • 1,292
  • 1
  • 17
  • 40