umeng友盟消息推送功能集成(本人使用的是eclipse开发)
1.首先请自行观看友盟消息推送集成的API文档。
观看地址如下:
2.集成步骤如下
- 下载sdk
注意:有两种sdk如果用户已经集成支付宝的就下载no-uid版本的sdk
下载地址:http://download.csdn.net/detail/lr393993507/9634730
- 解压下载好的文件,并且把 PushSDK 和 eclipselibs 两文件夹下的libs包拷贝到android的lib目录下
如图
- 修改android下的AndroidManifest.xml文件
增加如下内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.umeng.message.lib"
android:versionCode="1"
android:versionName="1.0" > <!-- 必选 -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- 可选 -->
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" /> <application android:allowBackup="true" >
<receiver
android:name="com.umeng.message.NotificationProxyBroadcastReceiver"
android:exported="false" >
</receiver>
<receiver
android:name="com.umeng.message.SystemReceiver"
android:process=":push" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" />
</intent-filter>
</receiver>
<receiver
android:name="com.umeng.message.MessageReceiver"
android:exported="false"
android:process=":push" >
<intent-filter>
<action android:name="org.agoo.android.intent.action.RECEIVE" />
</intent-filter>
</receiver>
<receiver
android:name="com.umeng.message.ElectionReceiver"
android:process=":push" >
<intent-filter>
<action android:name="org.agoo.android.intent.action.ELECTION_RESULT_V4" /> <category android:name="umeng" />
</intent-filter>
</receiver>
<receiver
android:name="com.umeng.message.RegistrationReceiver"
android:exported="false" >
<intent-filter>
<action android:name="${applicationId}.intent.action.COMMAND" />
</intent-filter>
</receiver>
<receiver android:name="com.umeng.message.UmengMessageBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> <service
android:name="com.umeng.message.UmengService"
android:exported="true"
android:label="PushService"
android:process=":push" >
<intent-filter>
<action android:name="${applicationId}.intent.action.START" />
</intent-filter>
<intent-filter>
<action android:name="${applicationId}.intent.action.COCKROACH" />
</intent-filter>
<intent-filter>
<action android:name="org.agoo.android.intent.action.PING_V4" /> <category android:name="umeng" />
</intent-filter>
</service>
<service
android:name="com.umeng.message.UmengIntentService"
android:process=":push" />
<service
android:name="com.umeng.message.UmengMessageIntentReceiverService"
android:exported="true"
android:process=":push" >
<intent-filter>
<action android:name="org.android.agoo.client.MessageReceiverService" />
</intent-filter>
<intent-filter>
<action android:name="org.android.agoo.client.ElectionReceiverService" />
</intent-filter>
</service>
<service
android:name="com.umeng.message.UmengMessageCallbackHandlerService"
android:exported="false" >
<intent-filter>
<action android:name="com.umeng.messge.registercallback.action" />
</intent-filter>
<intent-filter>
<action android:name="com.umeng.message.unregistercallback.action" />
</intent-filter>
<intent-filter>
<action android:name="com.umeng.message.message.handler.action" />
</intent-filter>
<intent-filter>
<action android:name="com.umeng.message.autoupdate.handler.action" />
</intent-filter>
</service>
<!-- If you donot want to use the standard notification bar in SDK, you can define IntentService instead to handle message. --> <service
android:name="com.umeng.message.UmengDownloadResourceService"
android:exported="false" />
<service
android:name="com.umeng.message.local.UmengLocalNotificationService"
android:exported="false" />
</application> </manifest>
注意:
- 把PushSDK目录下的
AndroidManifest.xml
中的${applicationId}
替换成为自己项目的包名。 - 右键单击PushSDK的libs目录下的jar文件,选择add to build path(若使用最新版本的ADT工具,则会自动将libs目录下的jar包添加到build path,无需执行此步骤)。
- 在自己工程目录下找到
project.properties
,在里面加入manifestmerger.enabled=true
,同时使主工程的minSdkVersion、targetSdkVersion与PushSDK的minSdkVersion、targetSdkVersion保持一致。
配置Appkey和Secret
在工程的Application Module里的AndroidManifest.xml中的<Application>
标签下添加:
<meta-data
android:name="UMENG_APPKEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
</meta-data>
<meta-data
android:name="UMENG_MESSAGE_SECRET"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
</meta-data>
把上述的UMENG_APPKEY
和UMENG_MESSAGE_SECRET
的值修改为和自己应用对应的值。
初始化PushSDK
务必
在工程的Application类的 onCreate()
方法中开启推送服务,无论推送是否开启都需要调用此方法:
mPushAgent = PushAgent.getInstance(this);
mPushAgent.onAppStart();
mPushAgent.enable();
String device_token = UmengRegistrar.getRegistrationId(this);//获取手机device token 唯一的
然后打包生成app,开始消息推送功能测试!