android开发 友盟推送点击Notification使用WebView加载url同时会调用系统浏览器的问题

来源:互联网 发布:jquery.poshytip.js 编辑:程序博客网 时间:2024/06/03 11:16

项目中需要使用友盟推送操作一些数据,使用的是WebVeiw加载h5页面显示数据,刚开始使用UmengNotificationClickHandler的openUri方法做跳转加载页面数据的操作,不管在WebView怎么处理,
系统浏览器总是会被调用,研究了很久,最后采用自定义(服务端也要采用自定义方案)方法,系统浏览器才没有被调用:

public void launchApp(Context context, UMessage msg);public void openUrl(Context context, UMessage msg);public void openActivity(Context context, UMessage msg);public void dealWithCustomAction(Context context, UMessage msg);

这四个方法,分别对应于四种打开方式。其中,launchApp、openUrl、openActivity这三个方法已经由消息推送SDK完成,而dealWithCustomAction则只是一个空的方法。 若开发者需要处理自定义行为,则可以重写方法dealWithCustomAction();其中自定义行为的内容,存放在UMessage.custom中。

服务器把h5页面连接放在custom中传递给我,我在dealWithCustomAction方法中处理获取custom值,然后打开,这样就不会调用系统浏览器,刚开始找错了方向,一直以为是WebView设置问题…

 UmengNotificationClickHandler umengNotificationClickHandler = new UmengNotificationClickHandler() {            /**             * 友盟推送通知点击事件的操作 使用此方法会导致WebView加载url的同事调用系统浏览器加载url,             * @param context             * @param uMessage             */          /*  @Override            public void openUrl(Context context, UMessage uMessage) {                super.openUrl(context, uMessage);                ToastUtil.defaultToast(getApplicationContext(),"openUrl()");                Intent intent=new Intent(getApplicationContext(), LoadUriActivity.class);                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                intent.putExtra("titleText","预约订单");                intent.putExtra("url",uMessage.url.toString());                shared.putString(Contants.WebUrl.OPEN_URI,uMessage.url);                shared.putString(Contants.WebUrl.OPEN_TITLE,"预约订单");                ToastUtil.defaultToast(getApplicationContext(),uMessage.url);                startActivity(intent);            }*/            @Override            public void dealWithCustomAction(Context context, UMessage uMessage) {                super.dealWithCustomAction(context, uMessage);                Intent intent = new Intent(getApplicationContext(), LoadUriActivity.class);                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                shared.putString(Contants.WebUrl.OPEN_URI, uMessage.custom);                shared.putString(Contants.WebUrl.OPEN_TITLE, "预约订单");                startActivity(intent);            }        };        PushAgent.getInstance(getApplicationContext()).setNotificationClickHandler(umengNotificationClickHandler);

此方法写在自定义Application类的OnCreate方法中

1 0
原创粉丝点击