Откройте действие, чтобы редактировать контакт в синхронизации

StackOverflow https://stackoverflow.com/questions/8344841

Вопрос

В 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

Я добавил контакт, и я вижу запись, но когда я нажимаю на нее, ничего не происходит. Что я должен сделать, чтобы начать деятельность, когда пользователь нажимает на него? Я пытался сделать то, что предлагается Здесь Для устройств перед домохонями: Хитрость заключается в том, чтобы вставить строку данных, «Изменить в 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>

Другие советы

Это то, что я сделал. В манифест

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

Первый будет транслироваться, когда пользователь нажимает на действие профиля, которое я добавил в свои учетные записи адаптеров с использованием кода в примере адаптера синхронизации (см. Выше)

Второй позволяет вам обрабатывать намерение, которое придерживается нативной адресной книги, когда пользователь хочет отредактировать контакт. Учтите это в первом случае, потому что миметип заключается в том, что один из ваших синхедиаптеров ваша деятельность будет вызвана напрямую. Во втором случае диалог будет показан со списком приложений, зарегистрированных для обработки android.intent.action.edit для Android: mimeType = "vnd.android.cursor.item/person", Android: MimeType = "vnd.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