I am developing android app where I need to add custom row in particular contacts of my app.Till now I am able to add row in my contact but when I click on that row it does not open my application instead it show toast something like this: "No application found to handle this action".
I googled it a lot but no luck.
Here is my code: Method to add custom row in specific contact:
private void addContact(Account account, ContactDTO dto) {
Log.e("addContact", "dto : " + dto.displayName + " & dto : " + dto.contactID);
Log.e("addContact", "account.name : " + account.name + " & account.type : " + account.type);
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
builder.withValue(RawContacts.SYNC1, dto.displayName);
operationList.add(builder.build());
builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
builder.withValueBackReference(Data.RAW_CONTACT_ID, 0);
builder.withValue(Data.MIMETYPE, getResources().getString(R.string.mimeType));
builder.withValue(Data.DATA1, dto.displayName);
builder.withValue(Data.DATA2, dto.phoneNo);
builder.withValue(Data.DATA3, "View App");
operationList.add(builder.build());
operationList.add(ContentProviderOperation.newUpdate(AggregationExceptions.CONTENT_URI)
.withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER)
.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID1, 0)
.withValue(AggregationExceptions.RAW_CONTACT_ID2, dto.contactID)
.withValue(AggregationExceptions.CONTENT_ITEM_TYPE, getResources().getString(R.string.mimeType))
.build());
try {
mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
} catch (OperationApplicationException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.demosample">
<uses-permission
android:name="android.permission.AUTHENTICATE_ACCOUNTS"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter android:icon="@drawable/ic_launcher">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:icon="@drawable/ic_launcher">
<!--<action android:name="android.intent.action.VIEW" />-->
<action android:name="android.intent.action.VIEW" />
<action android:name="fm.last.android.sync.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="vnd.android.cursor.item/fm.last.android.sync.login" />
<!--<data android:host="ccc.in.demosample.mainactivity" />-->
<!--<data android:scheme="http" />-->
<!--<data android:pathPattern="/.*" />-->
<data android:mimeType="vnd.android.cursor.item/fm.last.android.sync.login" />
</intent-filter>
</activity>
<service
android:name=".AccountAuthenticatorService"
android:exported="true"
android:process=":auth">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<service
android:name=".ContactsSyncAdapterService"
android:exported="true"
android:process=":contacts">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/sync_contacts" />
<meta-data
android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts" />
</service>
</application>
</manifest>
contacts.xml
<?xml version="1.0" encoding="utf-8"?>
<ContactsSource xmlns:android="http://schemas.android.com/apk/res/android">
<ContactsDataKind
android:detailColumn="data3"
android:detailSocialSummary="true"
android:mimeType="vnd.android.cursor.item/fm.last.android.sync.login"
android:summaryColumn="data2" />
</ContactsSource>
account_preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
</PreferenceScreen>
authenticator.xml
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountPreferences="@xml/account_preferences"
android:accountType="@string/ACCOUNT_TYPE"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:smallIcon="@drawable/ic_launcher" />
sync_contacts.xml
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/ACCOUNT_TYPE"
android:contentAuthority="com.android.contacts"
android:supportsUploading="false" />
That's it. Please let me know where I am going wrong. Above code will add custom row in contact without application icon and by clicking on that row it will show a toast and will not open my application.
I was having the same issue in marshmallow devices. The only thing which worked was to change the mimeType.
Try changing your mimeType from
to
Do this change wherever you have used.