質問

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

/**
 * 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>  

ここで、samplysyncadaptercolumns.mime_profile = vnd.android.cursor.item/vnd.myapp.profile

連絡先を追加して、エントリを見ることができますが、クリックすると何も起こりません。ユーザーがクリックしたときにアクティビティを開始するにはどうすればよいですか?私は提案されていることをしようとしていました ここ 在庫前のデバイスの場合: 秘trickは、データの行、「myAppで編集」を挿入することです。

役に立ちましたか?

解決

あなたの意図フィルターが間違っているかもしれないと思います。によると このエントリ, 、正しいアクションとデータ項目は、次のようなものでなければなりません。

<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>

他のヒント

これが私がしたことです。マニフェストファイルで、私のアクティビティの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>            

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

2番目の場合、ユーザーが連絡先を編集したいときにネイティブアドレス帳によってBoradcastcastである意図を処理できます。 Mimetypeは、あなたのシンカダプターの1つがアクティビティが直接呼び出されることであるため、最初のケースでは考えてください。 2番目のケースでは、Android.intent.action.edit for android:vnd.android.cursor.item/person "、android:mimetype =" vnd.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.android.androidを処理するために登録されているアプリケーションのリストにダイアログが表示されます。 .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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top