1 创建新工程

-----获取api key 和secret key

phonegap 百度云推

2,推送设置

phonegap 百度云推

 

3,新建安卓项目,并把应用包名 和 推送中设置的包名设置一致

4,下载百度云客户端sdk

5,解压,并添加libs文件夹文件到相应路径,并添加pushservice-4.2.0.63.jar到构建路径

6,添加 Demo\src\com\baidu\push\example 路径下的Utils.java到 包下

7,新建MyPushMessageReceiver类并继承FrontiaPushMessageReceiver

8,根据提示初始化所有方法,并复写onNotificationClicked方法

/**
     * 接收通知点击的函数。注:推送通知被用户点击前,应用无法通过接口获取通知的内容。
     * 
     * @param context
     *            上下文
     * @param title
     *            推送的通知的标题
     * @param description
     *            推送的通知的描述
     * @param customContentString
     *            自定义内容,为空或者json字符串
     */
    @Override
    public void onNotificationClicked(Context context, String title,
            String description, String customContentString) {
        String notifyString = "通知点击 title=\"" + title + "\" description=\""
                + description + "\" customContent=" + customContentString;
        Log.d(TAG, notifyString);

        // 自定义内容获取方式,mykey和myvalue对应通知推送时自定义内容中设置的键和值
        if (!TextUtils.isEmpty(customContentString)) {
            JSONObject customJson = null;
            try {
                customJson = new JSONObject(customContentString);
                String myvalue = null;
                if (customJson.isNull("mykey")) {
                    myvalue = customJson.getString("mykey");
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
        updateContent(context, notifyString);
    }

    private void updateContent(Context context, String content) {

        MainActivity.url="http://www.sina.com";
        MainActivity.num=1;
        Intent intent = new Intent();
        intent.setClass(context.getApplicationContext(), MainActivity.class);
        
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        
        context.getApplicationContext().startActivity(intent);

        
    }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-11-28
  • 2022-02-19
  • 2022-01-16
  • 2021-05-29
  • 2022-12-23
猜你喜欢
  • 2021-06-29
  • 2021-12-12
  • 2022-02-18
相关资源
相似解决方案