How to open url in webview when onesignal push notification is send, right now it opens in the default browser and how to handle the target url by using notification handler. Here is the sample code where I want to implement onesignal notification and I tried my level best could not handle with it. Any suggestion from experts.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OneSignal.startInit(this).init();
}
handling
Here is my implementation... I added this code in my Application class onCreate()
OneSignal.startInit(this).setNotificationOpenedHandler(new OneSignal.NotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenResult result) {
String launchURL = result.notification.payload.launchURL;
if (launchURL != null) {
Log.d(Const.DEBUG, "Launch URL: " + launchURL);
Intent intent = new Intent(getApplicationContext(), WebViewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("url", launchURL);
startActivity(intent);
} else {
Log.d(Const.DEBUG, "Launch URL not found");
Intent intent = new Intent(getApplicationContext(), SplashActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}).init();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With