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. 从Config文件中读取节点的配置信息

    下面是web.config中与本内容有关的细节 <appSettings> <add key="servername" value="www" ...

  2. UVA 11181 dfs 概率

    N friends go to the local super market together. The probability of their buying something from them ...

  3. node中的模块

    模块 编写稍大一点的程序时一般都会将代码模块化.在NodeJS中,一般将代码合理拆分到不同的JS文件中,每一个文件就是一个模块,而文件路径就是模块名. 在编写每个模块时,都有require.expor ...

  4. Sold out

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

  5. phpstorm安装,破解及使用

    小黑小波比.下载安装phpstorm以及破解 PHPStorm下XDebug配置 phpstorm官方下载地址 PhpStorm 注册码 2.在这输入用户名和注册码,点击OK 破解成功! phpsto ...

  6. Android 核心分析之十三Android GWES之Android窗口管理

    Android GWES之Android窗口管理1基本构架原理 Android的窗口管理是C/S模式的.Android中的Window是表示Top Level等顶级窗口的概念.DecorView是Wi ...

  7. 针对安卓java入门:方法的使用

    [修饰符]返回值类型 方法名 (形式参数表){ 程序代码; return 返回值; } 例子: public class Test { //方法一 public static void printIn ...

  8. 在Ogre中加载自己的资源包

    转自:http://www.cnblogs.com/minggoddess/archive/2011/02/19/1958472.html 由于数据保护的需要,一款游戏一般都会有自己独有的资源包,这样 ...

  9. JVM垃圾回收机制总结(6) :透视Java的GC特性

    1. 使用 System.gc() 可以不管JVM使用的是哪一种垃圾回收的算法,都可以请求 Java的垃圾回收. 在命令行中有一个参数-verbosegc可以查看Java使用的堆内存的情况,它的格式: ...

  10. Ubuntu安装取色软件

    sudo apt-get install Gpick