6

I want to call Webview_activity on Notification Tap when app is killed , so in NotificationExtender Service ive attached Pending intent with the builder using setContentIntent() method, but nothing happens when notification is tapped.

Webview_activity is successfully called when application is alive, as that is handled by notificationOpened(), but when app is killed, onNotificationProcessing() is called but on Notification tap Webview_activity is not called.

I also read that Onesignal do not detect the setContentIntent() when attached to the builder here is the link : https://github.com/OneSignal/OneSignal-Android-SDK/issues/511 is there a way around? how can i call my activity on notification tap using onNotificationProcessing() of NotificationExtender Service when app is killed.

 @Override
    protected boolean onNotificationProcessing(final OSNotificationReceivedResult notification) {
        Log.d(TAG, "onNotificationProcessing");
        final NotificationCompat.Builder[] newbuilder = new NotificationCompat.Builder[1];
        OverrideSettings overrideSettings = new OverrideSettings();
        overrideSettings.extender = new NotificationCompat.Extender() {
            @Override
            public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
                // Sets the background notification color to Green on Android 5.0+ devices.
                newbuilder[0] = builder;
                Intent intent = new Intent();
                try {
                    JSONObject data = notification.payload.additionalData;
                    if (data != null) {
                        String url = data.optString("url", null);
                        if (url != null) {
                            if (getApplicationContext() != null) {
                                Log.d(TAG, "context is not null");
                                intent = new Intent(getApplicationContext(), Webview_activity.class);
                                intent.putExtra("url", url);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                            } else {
                                Log.d(TAG, "context is null");
                            }
                        }
                    }

                    **PendingIntent pendIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                    newbuilder[0] = builder.setContentIntent(pendIntent);**

                } catch (Exception e) {
                    e.printStackTrace();
                }
                return newbuilder[0];
            }
        };

        overrideSettings.extender.extend(newbuilder[0]);
        OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
        Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);

        return true;
    }




@Override
    public void notificationOpened(OSNotificationOpenResult result)
    {
        Log.d(TAG,"notificationOpened");
        try {
            JSONObject data = result.notification.payload.additionalData;
            if (data != null) {
                String url = data.optString("url", null);
                if (url != null) {
                    if (context!=null)
                    {
                        Log.d(TAG,"context is not null");
                        Intent intent = new Intent(context, Webview_activity.class);
                        intent.putExtra("url", url);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(intent);
                    }else {
                        Log.d(TAG,"context is null");
                    }
                }
            }
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }
Karan Gada
  • 65
  • 7

0 Answers0