“友達発見(Find Your Friends)” 機能では、ユーザーはアドレス帳をアップロードして、アプリでDigits機能を使っている知り合いのユーザーを探すことができます。
Digits: Find Your FriendsUsing the “Find Your Friends” feature, users can upload their address book to find other Digits users in your app that they know. |
マニフェストファイルにandroid.permission.READ_CONTACTSのアクセス権を追加しなければなりません。
これをしないと、Digits 機能はユーザーのアドレス帳にアクセスすることができません。
“友達発見(Find Your Friends)”を開始するには、プロセスでstartContactsUpload メソッドを実行します。
startContactsUploadに、必要に応じてカスタムテーマを付けて実行できます。
Digits.getInstance().getContactsClient().startContactsUpload();
startContactsUploadを初めて実行した時、ユーザーのアドレス帳をアップロードする許可を求めるダイアログが表示されます。
“Okay”とクリックすると、アドレス帳はIntentServiceを使ってバックグラウンドでアップロードされます。
Getting startedYou must include the To start the “Find Your Friends” process call the Digits.getInstance().getContactsClient().startContactsUpload(); The first time
Once the user clicks “Okay” the address book will be upload in the background using an |
接続が完了した後、成功した場合はcom.digits.sdk.android.UPLOAD_COMPLETEのアクション値が付いたIntentが送信され、失敗した場合はcom.digits.sdk.android.UPLOAD_FAILEDのアクション値が付いたIntentが送信されます。成功時には Intentは追加の情報も保持しています。
BroadcastReceiverを作成してIntentを受け取り、何らかの動作を処理することができます。
public class MyResultReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (ContactsUploadService.UPLOAD_COMPLETE.equals(intent.getAction())) {
ContactsUploadResult result = intent
.getParcelableExtra(ContactsUploadService.UPLOAD_COMPLETE_EXTRA);
// Post success notification
} else {
// Post failure notification
}
}
}
Getting resultsOnce complete the contacts upload service will broadcast an
public class MyResultReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (ContactsUploadService.UPLOAD_COMPLETE.equals(intent.getAction())) {
ContactsUploadResult result = intent
.getParcelableExtra(ContactsUploadService.UPLOAD_COMPLETE_EXTRA);
// Post success notification
} else {
// Post failure notification
}
}
}
|
BroadcastReceiverをアプリケーションマニフェストに追加するのを忘れないでください。
<receiver
android:name=".MyResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.digits.sdk.android.UPLOAD_COMPLETE"/>
<action android:name="com.digits.sdk.android.UPLOAD_FAILED"/>
</intent-filter>
</receiver>
|
Don’t forget to add your
<receiver
android:name=".MyResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.digits.sdk.android.UPLOAD_COMPLETE"/>
<action android:name="com.digits.sdk.android.UPLOAD_FAILED"/>
</intent-filter>
</receiver>
|
lookupContactMatches メソッドを実行することで結果を受け取ることができます。
Digits.getInstance().getContactsClient().lookupContactMatches(null, null,
new ContactsCallback<Contacts>() {
@Override
public void success(Result<Contacts> result) {
if (result.data.users != null) {
// Process data
}
}
@Override
public void failure(TwitterException exception) {
// Show error
}
});
|
Results can be retrieved by calling
Digits.getInstance().getContactsClient().lookupContactMatches(null, null,
new ContactsCallback<Contacts>() {
@Override
public void success(Result<Contacts> result) {
if (result.data.users != null) {
// Process data
}
}
@Override
public void failure(TwitterException exception) {
// Show error
}
});
|