快速配對隨附應用程式整合功能

快速配對功能可讓原始設備製造商 (OEM) 隨附應用程式深度整合,使其與配對和使用體驗深度整合。在使用者完成快速配對後,您可以選擇運用多個整合點與使用者互動。

在開箱體驗 (OOBE) 期間安裝

快速配對功能可讓使用者下載耳機的隨附應用程式,做為外箱體驗 (OOBE) 的最後一個步驟。系統會透過通知向使用者顯示這項通知,說明配對已完成,使用者可以選擇下載應用程式 (如果尚未安裝的話),或是開啟應用程式並開始使用。

如要開始使用此功能,請將隨附應用程式的套件名稱新增至控制台的裝置詳細資料中。

快速配對功能的隨附應用程式會額外提供資料元素:

  • android.bluetooth.device.extra.DEVICE:觸發通知的藍牙裝置

設定配量整合

Slices 可以由隨附應用程式提供,可進一步強化裝置藍牙設定頁面提供的選項。

SliceProvider 必須由隨附應用程式實作,才能提供這些設定配量。我們提供 2 種配量:OOBE 配量和一般設定項目。如果使用者尚未在隨附應用程式中設定耳機,而系統應一律納入其餘的配量,則應納入 OOBE 配量,詳情請參閱下方的程式碼範例:

@Nullable
@Override
public Slice onBindSlice(Uri sliceUri) {
  String address = sliceUri.getQueryParameter("addr");
  if (address == null) {
    return null;
  }
  String path = sliceUri.getPathSegments().get(/* index= */ 0);
  if ("settings_slice".equals(path)) {
    return createSettingSlice(sliceUri, address);
  } else if ("oobe_slice".equals(path)) {
    return createOobeReminderSlice(sliceUri, address);
  }
  return null;
}

oobe_slice 的用途是提醒使用者在隨附應用程式中完成設定裝置。如果使用者未在隨附應用程式中完成設定,隨附應用程式必須在使用者完成裝置設定後,再次提供該片段。

@Nullable
private Slice createOobeReminderSlice(Uri sliceUri, String address) {
  if (!deviceHasGoneThroughOobe(address)) {
    ListBuilder listBuilder =
        new ListBuilder(context, sliceUri, ListBuilder.INFINITY);
    addOobeSlice(listBuilder, context, address);
    return listBuilder.build();
  }
  return null;
}

private static void addOobeSlice(
    ListBuilder listBuilder, Context context, String address) {
  listBuilder.addRow(
      createRow(
          context,
          R.drawable.icon_oobe,
          R.string.title_oobe,
          R.string.summary_oobe,
          R.string.label_oobe,
          createOobePendingIntent(context, address)));
}

setting_slice 是隨附應用程式可以提供常用設定的連結。

private Slice createSettingSlice(Uri sliceUri, String address) {
  ListBuilder listBuilder =
      new ListBuilder(context, sliceUri, ListBuilder.INFINITY);
  // TODO: Add your customized slice here.
  addRow1(listBuilder, context, address);
  addRow2(listBuilder, context, address);
  return listBuilder.build();
}

private static void addRow1(
    ListBuilder listBuilder, Context context, String address) {
  listBuilder.addRow(
      createRow(
          context,
          R.drawable.fp_slice_row1_icon,
          R.string.fp_slice_row1_title_gestures,
          R.string.fp_slice_row1_summary_gestures,
          R.string.fp_slice_row1_label_gestures,
          createPendingIntent(context, address)));
}

private static void addRow2(
    ListBuilder listBuilder, Context context, String address) {
  ...
}

每個 Slice 都必須包含標題、副標題、圖示和動作。

private static RowBuilder createRow(
    Context context,
    @DrawableRes int iconId,
    @StringRes int titleId,
    @StringRes int summaryId,
    @StringRes int actionTitleId,
    PendingIntent pendingIntent) {
  SliceAction action =
      SliceAction.createDeeplink(
          pendingIntent,
          IconCompat.createWithResource(context, iconId),
          ListBuilder.ICON_IMAGE,
          context.getString(actionTitleId));
  return new RowBuilder()
      .setTitleItem(
          IconCompat.createWithResource(context, iconId),
          ListBuilder.ICON_IMAGE)
      .setTitle(context.getString(titleId))
      .setSubtitle(context.getString(summaryId))
      .setPrimaryAction(action);
}

實作 SliceProvider 後,請將以下內容新增至控制台,讓快速配對服務確認與正確的應用程式通訊:

韌體更新意圖

如果連線裝置的韌體版本過舊,或顯示的韌體版本與裝置主控台中設定的韌體版本不同,快速配對功能會在韌體版本檢查後透過 com.google.android.gms.nearby.fastpair.ACTION_FIRMWARE_UPDATE_BROADCAST 意圖通知隨附應用程式。意圖具有下列額外資訊:

  • com.google.android.gms.nearby.fastpair.EXTRA_LOCAL_FIRMWARE_VERSION,是已連線裝置的韌體版本
  • com.google.android.gms.nearby.fastpair.EXTRA_UPDATE_NOTIFICATION_SHOWN;如果快速配對功能顯示通知,請設為 true