Frage

Im Android -Probensyncadapter befindet sich das folgende Code:

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

Ich fügte dies als Filter für meine Aktivität hinzu

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

Wo probeSyncadapterColumns.mime_profile = vnd.android.cursor.item/vnd.myapp.profile

Ich habe einen Kontakt hinzugefügt und kann den Eintrag sehen, aber wenn ich darauf klicke, passiert nichts. Was soll ich tun, um eine Aktivität zu starten, wenn der Benutzer darauf klickt? Ich habe versucht zu tun, was vorgeschlagen wird Hier Für Geräte vor dem Honeycomb: Der Trick besteht darin, eine Datenzeile einzufügen, "in MyApp bearbeiten", die den Benutzer zu Ihrer App bringen würde, und Ihre App würde dann eine Editoraktivität bereitstellen

War es hilfreich?

Lösung

Ich denke, Ihr Absichtsfilter könnte falsch sein. Entsprechend Dieser Eintrag, Die richtige Aktion und Datenelemente sollten so etwas wie die folgenden sein:

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

Andere Tipps

Das habe ich getan. In der Manifest -Datei habe ich diese Absichtsfilter für eine meiner Aktivitäten hinzugefügt

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

Der erste wird ausgestrahlt, wenn der Benutzer auf die Profilaktion klickt, die ich in meinen Sync -Adapterkonten mit dem Code im Beispiel -Synchronisierungsadapter hinzugefügt habe (siehe oben).

Mit dem zweiten können Sie die Absicht verarbeiten, die vom nativen Adressbuch boradcastiert wird, wenn der Benutzer den Kontakt bearbeiten möchte. Beachten Sie das im ersten Fall, weil der Mimetyp ist, dass einer Ihrer Synkadapter Ihre Aktivität direkt aufgerufen wird. Im zweiten Fall wird ein Dialog mit der Liste der Anwendungen angezeigt, um die Android.intent.action.edit für Android zu verarbeiten: mimetyp .cursor.item/contact "usw.

In meiner Aktivität habe ich eine solche Methode:

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;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top