0

Android SampleSyncAdapterには、次のコードがあります。

/**
 * Adds a profile action
 *
 * @param userId the userId of the sample SyncAdapter user object
 * @return instance of ContactOperations
 */
public ContactOperations addProfileAction(long userId) {
    mValues.clear();
    if (userId != 0) {
        mValues.put(SampleSyncAdapterColumns.DATA_PID, userId);
        mValues.put(SampleSyncAdapterColumns.DATA_SUMMARY, mContext
            .getString(R.string.syncadapter_profile_action));
        mValues.put(SampleSyncAdapterColumns.DATA_DETAIL, mContext
            .getString(R.string.view_profile));
        mValues.put(Data.MIMETYPE, SampleSyncAdapterColumns.MIME_PROFILE);
        addInsertOp();
    }
    return this;
}

これをアクティビティのフィルターとして追加しました

    <intent-filter>
        <action android:name="@string/syncadapter_profile_action" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="vnd.android.cursor.item/vnd.myapp.profile"
            android:host="contacts" />
     </intent-filter>  

ここで、SampleSyncAdapterColumns.MIME_PROFILE = vnd.android.cursor.item / vnd.myapp.profile

連絡先を追加するとエントリが表示されますが、クリックしても何も起こりません。ユーザーがアクティビティをクリックしたときにアクティビティを開始するにはどうすればよいですか?ハニカム前のデバイスについて、 ここで提案されていることを実行しようとしました。トリックは、データ行「Edit in MyApp」を挿入することです。これにより、ユーザーがアプリに移動し、アプリがエディターアクティビティを提供します。

4

2 に答える 2

1

インテント フィルターが間違っている可能性があります。このエントリによると、正しいアクションとデータ項目は次のようになります。

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.item/vnd.myapp.profile" />
</intent-filter>
于 2011-12-06T17:13:52.157 に答える
1

これが私がしたことです。マニフェスト ファイルで、アクティビティの 1 つにこれらのインテント フィルターを追加しました

<intent-filter >
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />

    <data android:mimeType="vnd.android.cursor.item/vnd.myapp.profile" />
</intent-filter>

<intent-filter >
    <action android:name="android.intent.action.EDIT" />

    <category android:name="android.intent.category.DEFAULT" />

    <data
        android:host="contacts"
        android:mimeType="vnd.android.cursor.item/person" />
    <data
        android:host="com.android.contacts"
        android:mimeType="vnd.android.cursor.item/contact" />
    <data
        android:host="com.android.contacts"
        android:mimeType="vnd.android.cursor.item/raw_contact" />
</intent-filter>            

サンプル同期アダプターのコードを使用して同期アダプター アカウントに追加したプロファイル アクションをユーザーがクリックすると、最初のアクションがブロードキャストされます (上記を参照)。

2 つ目は、ユーザーが連絡先を編集したいときに、ネイティブ アドレス帳によってブロードキャストされるインテントを処理できるようにします。最初のケースでは、mimetype が syncadapter の 1 つであるため、アクティビティが直接呼び出されることを考慮してください。2 番目のケースでは、android:mimeType="vnd.android.cursor.item/person"、android:mimeType="vnd.android の android.intent.action.EDIT を処理するために登録されたアプリケーションのリストを示すダイアログが表示されます。 .cursor.item/contact」など

私の活動では、次のような方法があります。

boolean handleIntent(Intent intent) {
    String action = intent.getAction();

    Uri uri = intent.getData();
    if (action.equalsIgnoreCase(Intent.ACTION_VIEW)) {
        handleProfileAction(uri);  // in this case uri points to ProfileAction Data raw that is one of the Data that your sync adaoter has added in the raw contact 
    } else if (action.equalsIgnoreCase(Intent.ACTION_EDIT)) {
        editYourContact(uri); // in this case the uri points to the Contact containing you raw contact although at least on SonuEricsson  Xperia mini when this intent is broadcasted by the context menu "edit contact" command I receive the URI of the raw contact when there is only one.
    }
    return true;
}
于 2011-12-12T18:20:31.667 に答える