Find Friends (Deprecated)

Warning

Find Friends provided by Digits is not being migrated to Firebase Auth and will no longer work effective September 30th. For more information, please see our FAQ and migration guide.

Using the Find Friends feature, users can upload their address book to find other Digits users in your app that they know. If you want to allow users to Invite Friends to your app, please see Invite Friends (Deprecated).

Getting Started

You must include the android.permission.READ_CONTACTS permission in your manifest. Without this Digits will be unable to access the user’s address book.

To start the Find Friends process call the uploadContacts method on the Digits instance. You can optionally define Digits with a custom theme for the upload flow.

Digits.uploadContacts();

The first time uploadContacts is called a dialog requesting permission to upload the user’s address book will be displayed.

../_images/contacts.png

Once the user clicks “Okay” the address book will be upload in the background using an IntentService.

Getting Results

Once complete the contacts upload service will broadcast an Intent with the action value com.digits.sdk.android.UPLOAD_COMPLETE for success or com.digits.sdk.android.UPLOAD_FAILED for failure. On success the Intent will contain an extra value with additional information. You can create a BroadcastReceiver to receive the Intent and perform some action.

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

Don’t forget to add your BroadcastReceiver to the application manifest.

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

Results can be retrieved by calling findFriends method.

Digits.findFriends(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
    }
  });

Example

See the sample app’s Digits Main Activity for example usage.

Advanced

Call uploadContacts with an activity request id to bind a request code to the activity result.

public static final int CONTACT_UPLOAD_REQUEST = 2;
// ...
Digits.uploadContacts(CONTACT_UPLOAD_REQUEST);
// ...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CONTACT_UPLOAD_REQUEST && resultCode == RESULT_CANCELED) {
      // ...
    }
}