Skip to content

ディープリンク

Android SDK 実装プロセスの一環として、アプリがディープリンクを使用する機能を設定します。この記事では、ディープリンクのユースケースの追加例を紹介します。

ディープリンクの基本情報については、ユーザーガイドの記事を参照してください。

ユニバーサルディープリンクデリゲート

Android SDK は、コンテンツカード、アプリ内メッセージ、プッシュ通知にわたって Braze によって開かれたすべてのディープリンクをカスタム処理するように単一のデリゲートオブジェクトを設定する機能を提供しています。

デリゲートオブジェクトはIBrazeDeeplinkHandlerインターフェイスを実装し、BrazeDeeplinkHandler.setBrazeDeeplinkHandler()を使用して設定する必要があります。ほとんどの場合、デリゲートはアプリのApplication.onCreate()で設定する必要があります。

以下は、カスタムインテントフラグと YouTube URL のカスタム動作でデフォルトのUriAction動作を上書きする例です。

```java public class CustomDeeplinkHandler implements IBrazeDeeplinkHandler { private static final String TAG = BrazeLogger.getBrazeLogTag(CustomDeeplinkHandler.class);

@Override public void gotoNewsFeed(Context context, NewsfeedAction newsfeedAction) { newsfeedAction.execute(context); }

@Override public void gotoUri(Context context, UriAction uriAction) { String uri = uriAction.getUri().toString(); // 私たちのアプリではなく YouTube アプリで YouTube の URL を開く if (!StringUtils.isNullOrBlank(uri) && uri.contains(“youtube.com”)) { uriAction.setUseWebView(false); }

1
2
CustomUriAction customUriAction = new CustomUriAction(uriAction);
customUriAction.execute(context);   }

public static class CustomUriAction extends UriAction {

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public CustomUriAction(@NonNull UriAction uriAction) {
  super(uriAction);
}

@Override
protected void openUriWithActionView(Context context, Uri uri, Bundle extras) {
  Intent intent = getActionViewIntent(context, uri, extras);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  if (intent.resolveActivity(context.getPackageManager()) != null) {
    context.startActivity(intent);
  } else {
    BrazeLogger.w(TAG, "Could not find appropriate activity to open for deep link " + uri + ".");
  }
}   } } \`\`\`

```kotlin class CustomDeeplinkHandler :IBrazeDeeplinkHandler {

override fun gotoNewsFeed(context:Context, newsfeedAction:NewsfeedAction) { newsfeedAction.execute(context) }

override fun gotoUri(context:Context, uriAction:UriAction) { val uri = uriAction.uri.toString() // 私たちのアプリではなく YouTube アプリで YouTube の URL を開く if (!StringUtils.isNullOrBlank(uri) && uri.contains(“youtube.com”)) { uriAction.useWebView = false }

1
2
val customUriAction = CustomUriAction(uriAction)
customUriAction.execute(context)   }

class CustomUriAction(uriAction:UriAction) :UriAction(uriAction) {

1
2
3
4
5
6
7
8
9
override fun openUriWithActionView(context: Context, uri: Uri, extras: Bundle) {
  val intent = getActionViewIntent(context, uri, extras)
  intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
  if (intent.resolveActivity(context.packageManager) != null) {
    context.startActivity(intent)
  } else {
    BrazeLogger.w(TAG, "Could not find appropriate activity to open for deep link $uri.")
  }
}   }

companion object { private val TAG = BrazeLogger.getBrazeLogTag(CustomDeeplinkHandler::class.java) } } ```

アプリ設定へのディープリンク

ディープリンクでアプリの設定を直接開くようにするには、カスタムのBrazeDeeplinkHandlerが必要です。以下の例では、open_notification_pageと呼ばれるカスタムのキーと値のペアが存在すると、ディープリンクがアプリの設定ページを開きます。

```java BrazeDeeplinkHandler.setBrazeDeeplinkHandler(new IBrazeDeeplinkHandler() { @Override public void gotoUri(Context context, UriAction uriAction) { final Bundle extras = uriAction.getExtras(); if (extras.containsKey(“open_notification_page”)) { Intent intent = new Intent(); intent.setAction(“android.settings.APP_NOTIFICATION_SETTINGS”); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

1
2
3
4
5
6
7
8
  //for Android 5-7
  intent.putExtra("app_package", context.getPackageName());
  intent.putExtra("app_uid", context.getApplicationInfo().uid);

  // for Android 8 and later
  intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
  context.startActivity(intent);
}   }

@Override public void gotoNewsFeed(Context context, NewsfeedAction newsfeedAction) {} }); ```

```kotlin BrazeDeeplinkHandler.setBrazeDeeplinkHandler(object :IBrazeDeeplinkHandler { override fun gotoUri(context:Context, uriAction:UriAction) { val extras = uriAction.extras if (extras.containsKey(“open_notification_page”)) { val intent = Intent() intent.action = “android.settings.APP_NOTIFICATION_SETTINGS” intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

1
2
3
4
5
6
7
8
  //for Android 5-7
  intent.putExtra("app_package", context.packageName)
  intent.putExtra("app_uid", context.applicationInfo.uid)

  // for Android 8 and later
  intent.putExtra("android.provider.extra.APP_PACKAGE", context.packageName)
  context.startActivity(intent)
}   }

override fun gotoNewsFeed(context:Context, newsfeedAction:NewsfeedAction) {} }) ```

ニュースフィードへのディープリンク{#Android_Deep_Advance}

プッシュ通知から Braze ニュースフィードにディープリンクするには、ニュースフィードアクティビティのカスタムディープリンクを作成します。

次に、プッシュ通知キャンペーンを設定する際に (ダッシュボードまたは API を通じて) 、 ニュースフィードのディープリンクに移動するように通知を構成します。

カスタム WebView アクティビティ{#Custom_Webview_Activity}

デフォルトでは、Braze によってアプリ内でウェブサイトのディープリンクが開かれると、BrazeWebViewActivityによって処理されます。これを変更するには、以下を行います。

1.キーcom.braze.Constants.BRAZE_WEBVIEW_URL_EXTRAIntent.getExtras()から対象の URL を扱うアクティビティを新規作成します。例については、BrazeWebViewActivity.javaを参照してください。

2.そのアクティビティをAndroidManifest.xmlに追加し、exportedfalseに設定します。

1
2
3
<activity
    android:name=".MyCustomWebViewActivity"
    android:exported="false" />

3.カスタムアクティビティをBrazeConfigビルダーオブジェクトに設定します。ビルダーをビルドし、Application.onCreate()内のBraze.configure()に渡します。

1
2
3
4
5
BrazeConfig brazeConfig = new BrazeConfig.Builder()
    .setCustomWebViewActivityClass(MyCustomWebViewActivity::class)
    ...
    .build();
Braze.configure(this, brazeConfig);
1
2
3
4
5
val brazeConfig = BrazeConfig.Builder()
    .setCustomWebViewActivityClass(MyCustomWebViewActivity::class.java)
    ...
    .build()
Braze.configure(this, brazeConfig)
「このページはどの程度役に立ちましたか?」
New Stuff!