Home > database >  Receive Push Notifications for Web Apps running in a WebView
Receive Push Notifications for Web Apps running in a WebView

Time:11-17

I have implemented a "super app" for Android & iOS that opens various web apps in a WebView, allowing users to access standard services without having to leave the app.

The Flow

The user opens the Mobile App

The user selects a web app from the list of common apps like Facebook, Twitter, Deliveroo, Uber, and other shopping, food delivery, and ride-hailing apps.

The Problem

The web apps work fine for everything, however, the push notifications are not received by the WebView.

What I have tried

I have tried using Google Chrome Push Notifications for this. However, it only supports Chrome and it is not possible to receive these notifications in iframe or WebView.

What I Expect

I expect to be able to receive notifications from these web apps of various services I have integrated, as it is not 100% usable if my users are not able to get notifications for these web apps.

CodePudding user response:

step 1 ) webview data is saving,i think upto this you are coming.

step 2 ) connect with firebase

step 3 ) create like below FirebaseMessagingService.java, below is just example,

    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());
    }


}

step 4) call above FirebaseMessagingService.java in manifest.xml

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

step 5) also create instance id and channel .

step 6) enable cloud messaging and firebase function .

step 7) once firebase function is enabled , it calls in background and you/all will receive notification

try like this way, make some code , if still error , then edit question and add that error here, so we can easily solve this issue. comment if query.

CodePudding user response:

Pushy works pretty well. I don't know if your usecase specific does the Job. But may worth a try

Have a look in Pushy

  • Related