【问题标题】:How to implement OneSignal push notification that opens URL in webview rather than browser?如何实现在 webview 而不是浏览器中打开 URL 的 OneSignal 推送通知?
【发布时间】:2016-10-21 03:22:02
【问题描述】:

发送onesignal推送通知时如何在webview中打开url,现在它在默认浏览器中打开,以及如何使用通知处理程序处理目标url。这是我想实现一个信号通知的示例代码,我尽力了我的水平无法处理它。专家的任何建议。

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        OneSignal.startInit(this).init();
}

处理

【问题讨论】:

    标签: android android-fragments webview onesignal


    【解决方案1】:

    这是我的实现...我在我的应用程序类中添加了这段代码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();
    

    【讨论】:

      【解决方案2】:

      为此,您应该将您的网址设置为附加数据字段,而不是启动网址。

      接下来,您可以使用 OneSignal Android NotificationReceivedHandler 检索此附加数据并打开指向该 URL 的 Web 视图。

      【讨论】:

      • Gdeglin,谢谢 我们之前阅读了文档,问题是我们没有得到任何确切的文档或示例,因此实现单信号的特定功能非常复杂进入我们的。
      【解决方案3】:

      一种可能性是创建两种类型的消息,一种发送到浏览器,另一种发送到应用程序。 这个问题有一个如何做到这一点的例子: https://wordpress.org/support/topic/variable-launchurl/

      不确定它是否会对您的情况有所帮助,但我希望如此。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多