意图不是从联系人应用程序传递的



我正在开发Android应用,我需要在其中添加自定义行,特别是在我的应用程序的联系人中。不打开我的应用程序,它显示出类似的烤面包:"找不到处理此操作的应用程序"。

我谷歌搜索了很多,但没有运气。

这是我的代码:在特定联系人中添加自定义行的方法:

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();
        }
    }

subest.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" />

就是这样。请让我知道我出了什么问题。上面的代码将在没有应用程序图标的情况下添加自定义行,并单击该行,它将显示敬酒,并且不会打开我的应用程序。

我在棉花糖设备中遇到相同的问题。唯一有效的是更改模仿类型。

尝试从

更改模仿类型
<data android:mimeType="vnd.android.cursor.item/fm.last.android.sync.login" />

to

<data android:mimeType="vnd.android.cursor.item/vnd.fm.last.android.sync.login.profile" />

在您使用的任何地方进行此更改。

最新更新