1

I am trying to add new contact to android and receive this ActivityNotFoundException: No Activity to handle intent. I am pretty sure that I need to use intent filter to resolve this problem but have no idea how.

Intent addContactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
addContactIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "My Name");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, "123456789");
startActivity(addContactIntent);

Here is my manifest file:

<activity
    android:name=".MainActivity"
    android:label="@string/title_activity_main" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="application/com.example.android.beam"></data>
    </intent-filter>
    <intent-filter>
        <action android:name="com.android.contacts.action.SHOW_OR_CREATE_CONTACT" />
        <data android:scheme="mailto" />
        <data android:scheme="tel" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
ForeverNights
  • 631
  • 1
  • 7
  • 34
  • Hi check this post http://stackoverflow.com/questions/1895206/how-can-i-launch-the-add-contact-activity-in-android answer posted by "zwickilton" – vinay kumar Aug 25 '12 at 05:40

1 Answers1

2

try changing these to

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);

// Just two examples of information you can send to pre-fill out data for the // user. See android.provider.ContactsContract.Intents.Insert for the complete // list.

intent.putExtra(ContactsContract.Intents.Insert.NAME, "some Contact Name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "some Phone Number");

you will have to add this permission also

<uses-permission android:name="android.permission.READ_CONTACTS"/>
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Athul Harikumar
  • 2,501
  • 18
  • 16
  • however if i do this, the new contact would be forcefully added even without user's consent when they press back to my application. How to prevent it from happening? – ForeverNights Aug 25 '12 at 05:44
  • put an alert in your application for user consent if the permit go for the intent else do whatever you want to do in the negative btn space ;) – Athul Harikumar Aug 25 '12 at 05:53