Wovnプッシュ通知翻訳機能(自動翻訳)
注意: このドキュメントは主に Firebase Cloud Messaging を対象としています。Fanship などの別のサービスを使用している場合は、以下の関連セクションを参照するか、お問い合わせください。
このドキュメントでは、アプリケーションが既にプッシュ通知用に Firebase Cloud Messaging サービスに接続されていること を前提としています。まだ接続していない場合は、公式の Google ドキュメント に従ってください。
概要
このドキュメントでは、以下のことを学びます:
- WOVN が通知をどのように翻訳できるか
- エンドユーザーに表示する前にサーバーからの通知データにアクセスし、翻訳するために WOVN を許可する方法
- 敏感なユーザー情報を含む通知データを翻訳するために WOVN を使用する方法
- ローカルプッシュ通知を翻訳するために WOVN を使用する方法
- プッシュ通知に Fanship と WOVN を統合する方法
詳細
1. WOVN が通知をどのように翻訳できるか
- まず、テストデバイスにテストプッシュ通知を送信します。これにより、WOVN は通知データを WOVN ダッシュボードに 報告し、翻訳できるようになります。
- WOVN ダッシュボードが通知データを翻訳した後、同じ通知を再度テストデバイスに送信して確認します。
- 通知が翻訳されたことを確認したら、すべてのユーザーに通知を送信できます。
2. エンドユーザーに表示する前にサーバーからの通知データにアクセスし、翻訳するために WOVN を許可する方法
-
FirebaseMessagingService
を拡張してカスタムロジックを追加していない場合は、このドキュメント に従って拡張してください。 -
FirebaseMessagingService
を拡張したクラス内に以下のコードを追加します。WOVN およびその他の必要な依存関係をインポートすることを忘れないでください。@Override
public void handleIntent(Intent intentSrc) {
Intent intentDst = Wovn.translateFirebaseNotificationIntent(intentSrc);
final String title = intentDst.getStringExtra("title") == null
? intentDst.getStringExtra("gcm.notification.title")
: intentDst.getStringExtra("title");
final String body = intentDst.getStringExtra("body") == null
? intentDst.getStringExtra("gcm.notification.body")
: intentDst.getStringExtra("body");
showNotification(title, body);
}
public void showNotification(String title, String message) {
if( title != null || message != null ) {
Context context = getApplicationContext();
showNotification(context, title, message);
}
}
public static void showNotification(Context context, String title, String message) {
final String CHANNEL_ID = "MyChannelId";
final int NOTIFICATION_ID = 1;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Android Oreo 以降用の通知チャンネルを作成
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Channel Name", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
// 通知を作成
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.arrow_point_to_right)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true);
// 通知を表示
notificationManager.notify(NOTIFICATION_ID, builder.build());
// WOVN 用
lastNotiTitle = title;
lastNotiBody = message;
}