百度推送实现上面的功能,我自己在做的时候,按照api上面的介绍去实现,出现了很多的问题。
第一,在onNotificationClicked()方法里面,能获取到custom_content的参数,但是无法进行界面跳转
type不管设置成多少都无法进行跳转
第二,在type == 2的情况下,可以实现跳转到指定的界面,但是无法获取到custom_content的参数,
后面多次询问百度的技术支持,也没有得到解决方案。
解决:后面实在是没有办法的情况下,发现在type== 2的情况下,也就是自定义行为下,都先先调用的onNotificationClicked()方法,
所以,就在方法中缓存参数数据,在跳转的界面获取参数。最后实现了;之前在网上看了很多的方法都没能实现;
下面是实现的具体流程
让后台将推送的open_type设置成2, 也就是点击通知之后自定义进行跳转
将pkg_content 设置成你指定界面的uri , 可以在界面中通过getInten.toURI()的方法获取,然后简单的拼接一下就好
我的是 #Intent;action=com.baidu.action.guarantee_sendtimer;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.roi.wispower_tongchen/.view.activity.GuaranteeRepairedDetailActivity;end
action是自己定义的,可以任意制定,component是需要跳转的界面,其他参数可以保持不变就好;
然后在清单文件里面配置你想要跳转的activity 如下
1
2
3
4
5
6<!--推送测试--> <activity android:name=".view.activity.GuaranteeRepairedDetailActivity" > <intent-filter> <action android:name="com.baidu.action.guarantee_sendtimer" /> </intent-filter> </activity>
这里的action要和上面的action一样
然后就在onNotificationClicked()方法中获取你想要的参数(如下)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47// 获取参数并跳转到指定界面 // 自定义内容获取方式,mykey和myvalue对应通知推送时自定义内容中设置的键和值 if (!TextUtils.isEmpty(s2)) { JSONObject customJson = null; try { customJson = new JSONObject(s2); int id = 0; int statu = 0; int repairType = 0; if (!customJson.isNull("id")) { id = customJson.getInt("id"); } if (!customJson.isNull("statu")) { statu = customJson.getInt("statu"); } if (!customJson.isNull("repairType")) { repairType = customJson.getInt("repairType"); } Constant.PUSH_ID = id; Constant.PUSH_STATU = statu; Constant.PUSH_REPAIRTYPE = repairType; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
最后在activity中获取就可以了
1
2
3repairCode = Constant.PUSH_ID; statu = Constant.PUSH_STATU; repairType = Constant.PUSH_REPAIRTYPE;
经过测试之后是可以实现的。现在还没有找到更好的解决方法
最后
以上就是暴躁书包最近收集整理的关于百度消息推送点击跳转到指定界面的实现的全部内容,更多相关百度消息推送点击跳转到指定界面内容请搜索靠谱客的其他文章。
发表评论 取消回复