1 创建新工程

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

2,推送设置

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); }

9 修改AndroidManifest.xml文件

----------------------修改application节点 android:name="com.baidu.frontia.FrontiaApplication"

----------------------注册MyPushMessageReceiver类

xml文件如下

  <application android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="小洋"
android:name="com.baidu.frontia.FrontiaApplication">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name=".SplashActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="keyboardHidden" android:name=".GuideActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<activity android:name=".MainActivity" />
<activity android:configChanges="orientation|keyboardHidden" android:label="MediaViewActivity" android:name="com.baidu.android.pushservice.richmedia.MediaViewActivity" />
<activity android:configChanges="orientation|keyboardHidden" android:label="MediaListActivity" android:launchMode="singleTask" android:name="com.baidu.android.pushservice.richmedia.MediaListActivity" />
<receiver android:name="com.hn.esgj.MyPushMessageReceiver">
- <intent-filter>
-
<action android:name="com.baidu.android.pushservice.action.MESSAGE" />
<action android:name="com.baidu.android.pushservice.action.RECEIVE" />
<action android:name="com.baidu.android.pushservice.action.notification.CLICK" />
</intent-filter>
</receiver>
<receiver android:name="com.baidu.android.pushservice.PushServiceReceiver" android:process=":bdservice_v1">
- <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="com.baidu.android.pushservice.action.notification.SHOW" />
<action android:name="com.baidu.android.pushservice.action.media.CLICK" />
</intent-filter>
</receiver>
<receiver android:name="com.baidu.android.pushservice.RegistrationReceiver" android:process=":bdservice_v1">
- <intent-filter>
<action android:name="com.baidu.android.pushservice.action.METHOD" />
<action android:name="com.baidu.android.pushservice.action.BIND_SYNC" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<service android:exported="true" android:name="com.baidu.android.pushservice.PushService" android:process=":bdservice_v1">
- <intent-filter>
<action android:name="com.baidu.android.pushservice.action.PUSH_SERVICE" />
</intent-filter>
</service>
</application>

10 在主active的onCreate方法中 开启

    public void onCreate(Bundle savedInstanceState) {
try{
PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY, "KH2j92etnCvrO0WyDLUQob4z") ;
}catch (Exception e){ }
super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(), url, Toast.LENGTH_SHORT).show();
super.setBooleanProperty("loadInWebView", true);
super.loadUrl(url);
this.num=0;
this.url="file:///android_asset/www/index.html";
}

11,到百度控制台推送通知做测试

理论上成功,服务器端请下载相应的sdk

phonegap 百度云推的更多相关文章

  1. 百度云推送-服务端 C# SDK

    思路: 1.公司有项目需要做android和ios手机端推送消息的功能: 2.没有接触过这方面的知识,一头雾水,开始在网上一顿搜,网上倒是有不少解决方案,首先搜的是android的解决方案,因为ios ...

  2. 改写百度云推送SDK,PHP PEAR 包:Services_Baidu_Push

    iPhone使用apple push很方便,而Android很多厂商删除了google push,而且google在大陆连不上,所以要用别的办法. Android常见的推送服务商有:极光推送(http ...

  3. App之百度云推送

    集成SDK 下载最新的Android SDK压缩包并解压,在新建工程或已有工程中增加百度云推送功能. 我下载的是 ,里面有一个同名的文件夹,文件夹中有 导入云推送jar包和so文件: 将解压后的lib ...

  4. 百度云推送的Java实现

    推送现在基本APP都有,项目中要通知和消息,所以综合考虑用了百度云推送 Java实现步骤: 1. 下载 http://push.baidu.com/sdk/push_server_sdk_for_ja ...

  5. Android 高仿微信实时聊天 基于百度云推送

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38799363 ,本文出自:[张鸿洋的博客] 一直在仿微信界面,今天终于有幸利用百 ...

  6. 使用【百度云推送】第三方SDK实现推送功能具体解释

    之前介绍过怎样使用shareSDK实现新浪微博分享功能,今天介绍怎样使用百度云推送SDK实现Android手机后台推送功能. 执行效果例如以下 第一步,假设使用百度的SDK,当然要先成为百度的开发人员 ...

  7. Android推送 百度云推送 入门篇

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/27231237 现在app基本都有推送的功能,于是看了下百度云的推送,官方文档和D ...

  8. 消息推送之百度云推送Android集成与使用方法

    这两天由于项目需要,研究了一下百度云推送,本来这事没什么多大工作量的,但注册百度开发者账户创建应用令我蛋疼菊紧了好一阵,这些东西做了对技术没啥提升,不做又不行,必经之路.好在我耗费了N多个毫毫秒秒后稀 ...

  9. 解决百度云推送通知,不显示默认Notification

    问题:百度云推送通知,不显示默认Notification 描述:采用推送消息的方式,可以在onMessage方法里面获取到推送的消息.另外推送通知也有获取到内容,后台日志也有show private ...

随机推荐

  1. POJ 1300 Door Man(欧拉回路的判定)

    题目链接 题意 : 庄园有很多房间,编号从0到n-1,能否找到一条路径经过所有开着的门,并且使得通过门之后就把门关上,关上的再也不打开,最后能回到编号为0的房间. 思路 : 这就是一个赤裸裸的判断欧拉 ...

  2. dom对象详解--document对象(二)

       dom对象详解--style对象 style对象 style对象和document对象下的集合对象styleSheets有关系,styleSheets是文档中所有style对象的集合,这里讲解的 ...

  3. sql主键的一点重要理解

    sql只会读取数据,不会自动设置主键,所以绑定数据后要设置主键(前台) 不管是int或者uniqueidentifier只要类型对得上就可以用,int自增其实没什么太大优势(但是通常都会用自增来做,从 ...

  4. C# 任意类型数据转JSON格式

    /// <summary> /// List转成json /// </summary> /// <typeparam name="T">< ...

  5. android-non-ui-ui-thread-communications-part-5-5

    This is the last post in my series regarding Android thread communications.  Parts 1 through 4 are l ...

  6. wamp中的phpmyadmin打开出现:#1045 - Access denied for user 'root'@'localhost' (using password: NO)

    详细内容: MySQL said: #1045 - Access denied for user 'root'@'localhost' (using password: NO) phpMyAdmin ...

  7. SQLHelper.cs的经典代码-存储过程

    using System; using System.Collections.Generic; using System.Text; using System.Collections; using S ...

  8. qt之透明提示框(模拟qq) (非常漂亮)

    Qt实现类似QQ的登录失败的提示框,主要涉及窗口透明并添加关闭按钮,以及图标和信息的显示等. 直接上代码: #include "error_widget.h" ErrorWidge ...

  9. Java:IO流与IO设备

    打印流:PrintWriter和PrintStream 特点:可以直接操作输入流和文件 //例子1:使用PrintStream将格式化的日期打印到文件中 import java.io.*; impor ...

  10. Android addRule()

    布局中有很多特殊的属性,通常在载入布局之前,在相关的xml文件中进行静态设置即可. 但是,在有些情况下,我们需要动态设置布局的属性,在不同的条件下设置不同的布局排列方式,这时候就需要用到 Relati ...