簡體   English   中英

接收在 WebView 中運行的 Web 應用程序的推送通知

[英]Receive Push Notifications for Web Apps running in a WebView

我已經為 Android 和 iOS 實現了一個“超級應用程序”,可以在 WebView 中打開各種 web 應用程序,允許用戶訪問標准服務而無需離開應用程序。

流動

用戶打開移動應用程序

用戶從 Facebook、Twitter、Deliveroo、Uber 以及其他購物、送餐和叫車應用等常用應用列表中選擇一個 web 應用。

問題

web 應用程序適用於所有應用程序,但 WebView 未收到推送通知。

我試過的

為此,我嘗試使用 Google Chrome 推送通知。 但是,它只支持 Chrome,無法在 iframe 或 WebView 中收到這些通知。

我期待什么

我希望能夠收到來自我集成的各種服務的這些 web 應用程序的通知,因為如果我的用戶無法收到這些 web 應用程序的通知,它不是 100% 可用。

Pushy 工作得很好。 我不知道您的用例是否特定於此工作。 但可能值得一試

看看 Pushy

步驟 1 ) webview 數據正在保存,我想你會來的。

步驟 2 ) 連接 firebase

第 3 步)像下面這樣創建 FirebaseMessagingService.java,下面只是示例,

    public class FirebaseMessagingService extends FirebaseMessagingService{

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

      //  showNotification(remoteMessage.getData().get("notification"));
    //    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
        showNotification( remoteMessage.getNotification().getBody(),remoteMessage.getNotification().getTitle());

    }

    private void showNotification(String Body ,String Title ) {

        Intent i = new Intent(this,MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)

                .setAutoCancel(false)
                .setContentTitle(Title)
                .setContentText(Body)
                .setSmallIcon(R.drawable.dd)
                .setContentIntent(pendingIntent);


        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        manager.notify(0,builder.build());
    }


}

步驟 4) 在 manifest.xml 中調用 FirebaseMessagingService.java

<service android:name=".FirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

步驟 5) 還創建實例 ID 和通道。

步驟 6) 啟用雲消息和 firebase function。

第 7 步)啟用 firebase function 后,它會在后台調用,您/所有人都會收到通知

像這樣嘗試,制作一些代碼,如果仍然錯誤,然后編輯問題並在此處添加該錯誤,這樣我們就可以輕松解決這個問題。 如果查詢,請發表評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM