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