我已整合了webview&我的应用中的通知。当在前台收到通知时,它会显示Toast,而在后台显示推送通知。
收到通知后,我想要app做两件事:
注意:用于通知的Firebase
以下是webview代码:
mWebview =(WebView) findViewById(R.id.webview1);
WebSettings webSettings = mWebview.getSettings();
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
mWebview.setWebViewClient(new CustomWebViewClient());
mWebview.loadUrl("http://example.com");
答案 0 :(得分:0)
EventBus
可以满足您的要求,您可以了解其用法。
https://github.com/greenrobot/EventBus
注册WebView的Activity,并创建一个方法。
EventBus.getDefault().register(this);
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(MessageEvent event) {/* Do something */};
单击通知发送消息,将回调onMessageEvent。
EventBus.getDefault().post(new MessageEvent());
答案 1 :(得分:0)
在活动中注册广播接收器并从Firebase Web服务发送Braodcast并在活动中接收它以更新webview
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
IntentFilter intentFilter = new IntentFilter(
"update_webview");
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//extract our message from intent
String msg_for_me = intent.getStringExtra("some_msg");
//log our message value
}
};
//registering our receiver
this.registerReceiver(mReceiver, intentFilter);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
//unregister our receiver
this.unregisterReceiver(this.mReceiver);
}
Now send Braodcast from FCM service where your received notification
Intent i = new Intent("update_webview").putExtra("some_msg", "I will be sent!");
this.sendBroadcast(i);