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. http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

    http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html

  2. Sold out

    When will the writer see the play? 'The play may begin at any moment,'I said. 'It may have begun alr ...

  3. C#DataGridView 美化

    private void dataGridView(DataGridView dataGridView) { System.Windows.Forms.DataGridViewCellStyle da ...

  4. 【PSR规范专题(4)】PSR-3 日志接口规范

    本文转自:https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-3-logger-interface-cn.md 本文制定了日志类库的通用接口规范. ...

  5. Hibernate笔记——(ONE TO ONE)一对一

    转自:http://ryxxlong.iteye.com/blog/622652 ================= 一对一(one-to-one)实例(Person-IdCard) 一对一的关系在数 ...

  6. Wireshark 网络抓包工具Wireshark的使用

    阅读目录 wireshark介绍 wireshark不能做的 wireshark VS Fiddler 同类的其他工具 什么人会用到wireshark wireshark 开始抓包 wireshark ...

  7. IME 编程相关

    以下内容摘自http://msdn.microsoft.com/zh-cn/goglobal/bb688135.aspx 在 Win32 中处理输入语言的方法 Microsoft Developer ...

  8. 开发ProxyServer的时候如何在一台PC上调试

    为了测试在真实的网络环境下你的ProxyServer性能如何,而你手头又只有一台电脑,怎么办? 打开你的ProxyServer(我用java写的,因此ProxyServer的进程是javaw.exe) ...

  9. protobuf php

    关于protobuf php,版本不知哪个好: https://github.com/yuangu/pb4php https://github.com/drslump/Protobuf-PHP htt ...

  10. js收藏

    //设为主页function SetHome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomeP ...