极光推送作用:

极光推送(JPush)是一个端到端的推送服务,使得服务器端消息能够及时地推送到终端用户手机上,让开发者积极地保持与用户的连接,从而提高用户活跃度、提高应用的留存率

主要作用:

保持与服务器的长连接,以便消息能够即时推送到达客户端

接收通知与自定义消息,并向开发者 App 传递相关信息

SDK 所支持的 Android 系统版本

目前 SDK 只支持 Android 2.3 或以上版本的手机系统;

富媒体信息流功能则需 Android 3.0 或以上版本的系统。

手动集成步骤:

手动集成压缩包下载链接:http://docs.jiguang.cn/jpush/resources/

  • 解压缩 jpush-android--3.x.x-release.zip 集成压缩包。
  • 复制 libs/jcore-android-x.x.x.jar 到工程 libs/ 目录下。
  • 复制 libs/jpush-android-3.x.x.jar 到工程 libs/ 目录下。
  • 复制 libs/(cpu-type)/libjcore1xy.so 到你的工程中存放对应 cpu 类型的目录下。
  • 复制 res/ 中 drawable-hdpi, layout, values 文件夹中的资源文件到你的工程中 res/ 对应同名的目录下。

共用了极光一键登入的jcore,就没有复制jcore-android-x.x.x.jar到lib下

说明 1:若没有 res/drawable-xxxx/jpush_notification_icon 这个资源默认使用应用图标作为通知 icon,在 5.0 以上系统将应用图标作为 statusbar icon 可能显示不正常,用户可定义没有阴影和渐变色的 icon 替换这个文件,文件名不要变。

说明 2:使用 android studio 的开发者,如果使用 jniLibs 文件夹导入 so 文件,则仅需将所有 cpu 类型的文件夹拷进去;如果将 so 文件添加在 module的libs 文件夹下,注意在 module 的 gradle 配置中添加一下配置:

sourceSets {main {jniLibs.srcDirs = ['libs']jniLibs.srcDirs = ['src/main/jniLibs']assets.srcDirs = ['src/main/assets', 'src/main/assets/']}
}

配置 AndroidManifest.xml

<receiverandroid:name=".message.JPushReceiver"android:enabled="true"><intent-filter android:priority="1000"><action android:name="cn.jpush.android.intent.REGISTRATION" /><!-- &lt;!&ndash; Required  用户注册SDK的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.UNREGISTRATION" /><action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /><!-- &lt;!&ndash; Required  用户接收SDK消息的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /><!-- &lt;!&ndash; Required  用户接收SDK通知栏信息的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /><!-- &lt;!&ndash; Required  用户打开自定义通知栏的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /><!-- &lt;!&ndash; Optional 用户接受Rich Push Javascript 回调函数的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.CONNECTION" /><!-- &lt;!&ndash; JPush 服务的连接状态发生变化。(注:不是指 Android 系统的网络连接状态。) 连接/断开 since 1.6.3 &ndash;&gt; --><category android:name="**********" /></intent-filter>
</receiver> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
<!-- Rich push 核心功能 since 2.0.6 -->
<activityandroid:name="cn.jpush.android.ui.PopWinActivity"android:exported="true"><intent-filter><category android:name="android.intent.category.DEFAULT" /><action android:name="cn.jpush.android.ui.PopWinActivity" /><category android:name="${applicationId}" /></intent-filter>
</activity> <!-- Required SDK核心功能 -->
<activityandroid:name="cn.jpush.android.ui.PushActivity"android:configChanges="orientation|keyboardHidden"android:exported="true"android:theme="@android:style/Theme.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.ui.PushActivity" /><category android:name="android.intent.category.DEFAULT" /><category android:name="${applicationId}" /></intent-filter>
</activity> <!-- Required SDK 核心功能 -->
<!-- 可配置android:process参数将PushService放在其他进程中 -->
<serviceandroid:name="cn.jpush.android.service.PushService"android:exported="false"android:process=":pushcore"><intent-filter><action android:name="cn.jpush.android.intent.REGISTER" /><action android:name="cn.jpush.android.intent.REPORT" /><action android:name="cn.jpush.android.intent.PushService" /><action android:name="cn.jpush.android.intent.PUSH_TIME" /></intent-filter>
</service> <!-- since 3.0.9 Required SDK 核心功能 -->
<providerandroid:name="cn.jpush.android.service.DataProvider"android:authorities="${applicationId}.DataProvider"android:exported="false"android:process=":pushcore" /> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,或把 enabled 设置成 false ;App 不会被其他 App 拉起,但会拉起其他的 App。 -->
<serviceandroid:name="cn.jpush.android.service.DaemonService"android:enabled="true"android:exported="true"><intent-filter><action android:name="cn.jpush.android.intent.DaemonService" /><category android:name="${applicationId}" /></intent-filter>
</service> <!-- 可选,如果使用静态Activity方式拉起,该组件必须声明 -->
<activityandroid:name="cn.jpush.android.service.DActivity"android:enabled="true"android:exported="true"android:taskAffinity="jpush.custom"android:theme="@android:style/Theme.Translucent.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.intent.DActivity" /><category android:name="${applicationId}" /></intent-filter>
</activity> <!-- since 3.1.0 Required SDK 核心功能 -->
<providerandroid:name="cn.jpush.android.service.DownloadProvider"android:authorities="${applicationId}.DownloadProvider"android:exported="true" /> <!-- Required SDK核心功能 -->
<receiverandroid:name="cn.jpush.android.service.PushReceiver"android:enabled="true"><intent-filter android:priority="1000"><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <!-- Required  显示通知栏 --><category android:name="${applicationId}" /></intent-filter><intent-filter><action android:name="android.intent.action.USER_PRESENT" /><action android:name="android.net.conn.CONNECTIVITY_CHANGE" /></intent-filter><!-- Optional --><intent-filter><action android:name="android.intent.action.PACKAGE_ADDED" /><action android:name="android.intent.action.PACKAGE_REMOVED" /><data android:scheme="package" /></intent-filter>
</receiver> <!-- Required SDK核心功能 -->
<receiverandroid:name="cn.jpush.android.service.AlarmReceiver"android:exported="false" />
<!--&lt;!&ndash; 3.5.0新增,用于定时展示功能 &ndash;&gt;<receiver android:name="cn.jpush.android.service.SchedulerReceiver" android:exported="false"/>
-->
<receiver android:name=".message.PushMessageReceiver"><intent-filter><action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /><category android:name="${applicationId}" /></intent-filter>
</receiver><activityandroid:name="cn.jpush.android.service.JNotifyActivity"android:exported="false"android:taskAffinity="jpush.custom"android:theme="@android:style/Theme.Translucent.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.intent.JNotifyActivity" /><category android:name="${applicationId}" /></intent-filter>
</activity> 

写自定义接受通知的类JPushReceiver

public class JPushReceiver extends BroadcastReceiver {//SDK 向 JPush Server 注册所得到的注册 IDpublic static final String EXTRA_REGISTRATION_ID = "cn.jpush.android.intent.REGISTRATION";//收到了自定义消息 Pushpublic static final String ACTION_MESSAGE_RECEIVED = "cn.jpush.android.intent.MESSAGE_RECEIVED";//收到了通知 Pushpublic static final String ACTION_NOTIFICATION_RECEIVED = "cn.jpush.android.intent.NOTIFICATION_RECEIVED";//用户点击了通知。 一般情况下,用户不需要配置此 receiver action。public static final String ACTION_NOTIFICATION_OPENED = "cn.jpush.android.intent.NOTIFICATION_OPENED";//用户点击了通知栏中自定义的按钮。(SDK 3.0.0 以上版本支持)public static final String ACTION_NOTIFICATION_CLICK_ACTION = "cn.jpush.android.intent.NOTIFICATION_CLICK_ACTION";//JPush 服务的连接状态发生变化。(注:不是指 Android 系统的网络连接状态。)public static final String ACTION_CONNECTION_CHANGE = "cn.jpush.android.intent.CONNECTION";private static final String TAG = "JIGUANG-Example";private MsgEvent msgEvent;public static final String CHANNEL_ID = "**************";private static final String CHANNEL_NAME = "Default Channel";private static final String CHANNEL_DESCRIPTION = "this is default channel!";private Context context;@Overridepublic void onReceive(Context context, Intent intent) {this.context = context;switch (intent.getAction()) {case EXTRA_REGISTRATION_ID://SDK 向 JPush Server 注册所得到的注册 IDbreak;case ACTION_MESSAGE_RECEIVED:break;case ACTION_NOTIFICATION_RECEIVED://收到了自定义消息 Push
//                onMessageReceived(context,intent);BaseNetTasks.JPUST_UNREAD_COUNT++; //全局的消息参数加1MsgEvent msgEvent = new MsgEvent(Constant.JPUST_NUM); //订阅事件处,显示全局的消息数msgEvent.setData(BaseNetTasks.JPUST_UNREAD_COUNT);EventBusManager.post(msgEvent);//收到了通知 PushonNotificationReceived(context, intent);break;case ACTION_NOTIFICATION_OPENED://用户点击了通知。 一般情况下,用户不需要配置此 receiver action。//openNotification(context, intent);break;case ACTION_NOTIFICATION_CLICK_ACTION://用户点击了通知栏中自定义的按钮。(SDK 3.0.0 以上版本支持)openNotification(context, intent);break;case ACTION_CONNECTION_CHANGE://JPush 服务的连接状态发生变化。(注:不是指 Android 系统的网络连接状态。)break;}}//点击通知栏的处理private void openNotification(Context context, Intent intent) {String extra = intent.getStringExtra(JPushInterface.EXTRA_EXTRA);NotifityContentBean bean = new Gson().fromJson(extra, NotifityContentBean.class); //NotifityContentBean根据后台发送的值自定义Intent targetIntent;switch (bean.key) {case "2":targetIntent = new Intent(context, PublishTaskManageListActivity.class);break;case "10":targetIntent = new Intent(context, ReceiveTaskManageListActivity.class);break;case "33":targetIntent = new Intent(context, PublishTaskManageListActivity.class);targetIntent.putExtra(Constant.ORDER_NAME, "接单订单");//标题break;...default:targetIntent = new Intent(context, MainActivity.class);}targetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);context.startActivity(targetIntent);}//收到通知private void onNotificationReceived(Context context, Intent intent) {onMessageReceived(context, intent);}private void onMessageReceived(Context context, Intent intent) {alertMsg(context, intent);}private void alertMsg(Context context, Intent intent) {if (intent != null) {//获取收到的通知内容String extra = intent.getStringExtra(JPushInterface.EXTRA_EXTRA);NotifityContentBean bean = new Gson().fromJson(extra, NotifityContentBean.class);String key = bean.key;String jpush_msg = bean.msg;String taskId = bean.taskId;String receiveId = bean.receiveId;int notifyId = (int) System.currentTimeMillis();Intent clickIntent = new Intent();clickIntent.putExtra(JPushInterface.EXTRA_EXTRA, extra);System.out.println("JPushInterface.EXTRA_EXTRA:" + extra);clickIntent.setAction(ACTION_NOTIFICATION_OPENED);PendingIntent contentIntent = PendingIntent.getBroadcast(context, notifyId, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);//重点:先创建通知渠道 (Android8.0及以上需要创建通知渠道)NotificationChannel mChannel = null;if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);               mChannel.setDescription(CHANNEL_DESCRIPTION);mChannel.setShowBadge(false);notificationManager.createNotificationChannel(mChannel);}//再创建通知NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID);notification.setAutoCancel(true).setOnlyAlertOnce(true).setContentTitle("xxxxx").setSmallIcon(R.mipmap.ic_launcher).setContentIntent(contentIntent);notification.setPriority(NotificationCompat.DEFAULT_ALL);if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {if (mChannel != null)notification.setChannelId(mChannel.getId());}notification.setContentText(jpush_msg); //  推送文本 if (!TextUtils.isEmpty(key)) {switch (key) {case "15"://顶号notification.setSound(Uri.parse(""));OtherUtil.cleanInfo(context);Intent mIntent = new Intent(context, NewLoginActivity.class);mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(mIntent);APPActivityManager.getAppManager().finishActivityUntilMain();return;...default:break;}}notificationManager.notify(notifyId, notification.build());Log.d("pushMmessage", "key=" + key + " receiveId=" + receiveId + " taskId=" + taskId + "   jpush_msg=" + jpush_msg);//弹窗显示通知popWindow(context, jpush_msg, key, taskId, receiveId);}}

}

为什么要对接厂商通道:

在程序没有被杀死的时候,能收到通知;在程序被杀死的时候,通知栏不显示通知,接收消息的代码也没有运行,处理不了消息

厂商通道的好处:(没有对接厂商通道,是极光服务器直接发送给手机;对接了厂商通道,进程存活的时候,是极光服务器直接发送给手机,进程没有存活的时候,极光服务器先发送给厂商,厂商通过自己的通知推送推送到手机)

在国内 Android 生态中,推送通道都是由终端与云端之间的长链接来维持,严重依赖于应用进程的存活状态。如今一些手机厂家会在自家 rom 中做系统级别的推送通道,再由系统分发给各个 app,以此提高在自家 rom 上的推送送达率。

接入极光厂商步骤

1.在极光后台点击推送设置,选择集成设置,选择Android,在厂商名称里选择填写华为,小米,OPPO,VIVO的相关厂商参数(在各大平台的软件信息里有),选择开启厂商通道

 2.按照极光文档对接,地址:http://docs.jiguang.cn/jpush/client/Android/huawei-Push-guide/

2.1 在根级 build.gradle 中添加规则

2.2 把third-push目录下libs中的需要的厂商jar拷贝其中的jar包至工程的libs目录下

2.3 配置小米推送sdk所需要的权

 <permissionandroid:name="您应用的包名.permission.MIPUSH_RECEIVE"android:protectionLevel="signature" /><uses-permission android:name="您应用的包名.permission.MIPUSH_RECEIVE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><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.READ_PHONE_STATE" /><uses-permission android:name="android.permission.GET_TASKS" /><uses-permission android:name="android.permission.VIBRATE" />

2.4配置组件和自定义服务(HWPushService华为,XMPushReceiver小米,OpenClickActivity 点击通知打开的Activity

<activityandroid:name=".message.activitys.OpenClickActivity"android:exported="true"android:launchMode="singleTop"><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /></intent-filter>
</activity>
<receiverandroid:name=".message.JPushReceiver"android:enabled="true"><intent-filter android:priority="1000"><action android:name="cn.jpush.android.intent.REGISTRATION" /><!-- &lt;!&ndash; Required  用户注册SDK的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.UNREGISTRATION" /><action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /><!-- &lt;!&ndash; Required  用户接收SDK消息的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /><!-- &lt;!&ndash; Required  用户接收SDK通知栏信息的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /><!-- &lt;!&ndash; Required  用户打开自定义通知栏的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /><!-- &lt;!&ndash; Optional 用户接受Rich Push Javascript 回调函数的intent &ndash;&gt; --><action android:name="cn.jpush.android.intent.CONNECTION" /><!-- &lt;!&ndash; JPush 服务的连接状态发生变化。(注:不是指 Android 系统的网络连接状态。) 连接/断开 since 1.6.3 &ndash;&gt; --><category android:name="************" /></intent-filter></receiver> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 --><!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 --><!-- Rich push 核心功能 since 2.0.6 --><activityandroid:name="cn.jpush.android.ui.PopWinActivity"android:exported="true"><intent-filter><category android:name="android.intent.category.DEFAULT" /><action android:name="cn.jpush.android.ui.PopWinActivity" /><category android:name="${applicationId}" /></intent-filter></activity> <!-- Required SDK核心功能 --><activityandroid:name="cn.jpush.android.ui.PushActivity"android:configChanges="orientation|keyboardHidden"android:exported="true"android:theme="@android:style/Theme.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.ui.PushActivity" /><category android:name="android.intent.category.DEFAULT" /><category android:name="${applicationId}" /></intent-filter></activity> <!-- Required SDK 核心功能 --><!-- 可配置android:process参数将PushService放在其他进程中 --><serviceandroid:name="cn.jpush.android.service.PushService"android:exported="false"android:process=":pushcore"><intent-filter><action android:name="cn.jpush.android.intent.REGISTER" /><action android:name="cn.jpush.android.intent.REPORT" /><action android:name="cn.jpush.android.intent.PushService" /><action android:name="cn.jpush.android.intent.PUSH_TIME" /></intent-filter></service> <!-- since 3.0.9 Required SDK 核心功能 --><providerandroid:name="cn.jpush.android.service.DataProvider"android:authorities="${applicationId}.DataProvider"android:exported="false"android:process=":pushcore" /> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 --><!-- 若不启用该功能可删除该组件,或把 enabled 设置成 false ;App 不会被其他 App 拉起,但会拉起其他的 App。 --><serviceandroid:name="cn.jpush.android.service.DaemonService"android:enabled="true"android:exported="true"><intent-filter><action android:name="cn.jpush.android.intent.DaemonService" /><category android:name="${applicationId}" /></intent-filter></service> <!-- 可选,如果使用静态Activity方式拉起,该组件必须声明 --><activityandroid:name="cn.jpush.android.service.DActivity"android:enabled="true"android:exported="true"android:taskAffinity="jpush.custom"android:theme="@android:style/Theme.Translucent.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.intent.DActivity" /><category android:name="${applicationId}" /></intent-filter></activity> <!-- since 3.1.0 Required SDK 核心功能 --><providerandroid:name="cn.jpush.android.service.DownloadProvider"android:authorities="${applicationId}.DownloadProvider"android:exported="true" /> <!-- Required SDK核心功能 --><receiverandroid:name="cn.jpush.android.service.PushReceiver"android:enabled="true"><intent-filter android:priority="1000"><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <!-- Required  显示通知栏 --><category android:name="${applicationId}" /></intent-filter><intent-filter><action android:name="android.intent.action.USER_PRESENT" /><action android:name="android.net.conn.CONNECTIVITY_CHANGE" /></intent-filter><!-- Optional --><intent-filter><action android:name="android.intent.action.PACKAGE_ADDED" /><action android:name="android.intent.action.PACKAGE_REMOVED" /><data android:scheme="package" /></intent-filter></receiver> <!-- Required SDK核心功能 --><receiverandroid:name="cn.jpush.android.service.AlarmReceiver"android:exported="false" /><!--&lt;!&ndash; 3.5.0新增,用于定时展示功能 &ndash;&gt;<receiver android:name="cn.jpush.android.service.SchedulerReceiver" android:exported="false"/>--><receiver android:name=".message.PushMessageReceiver"><intent-filter><action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /><category android:name="${applicationId}" /></intent-filter></receiver><activityandroid:name="cn.jpush.android.service.JNotifyActivity"android:exported="false"android:taskAffinity="jpush.custom"android:theme="@android:style/Theme.Translucent.NoTitleBar"><intent-filter><action android:name="cn.jpush.android.intent.JNotifyActivity" /><category android:name="${applicationId}" /></intent-filter></activity> <!-- 配置小米必须的组件 start --><serviceandroid:name="com.xiaomi.push.service.XMJobService"android:enabled="true"android:exported="false"android:permission="android.permission.BIND_JOB_SERVICE"android:process=":pushservice" /><serviceandroid:name="com.xiaomi.push.service.XMPushService"android:enabled="true"android:process=":pushservice" /><serviceandroid:name="com.xiaomi.mipush.sdk.PushMessageHandler"android:enabled="true"android:exported="true" /><serviceandroid:name="com.xiaomi.mipush.sdk.MessageHandleService"android:enabled="true" /><receiverandroid:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver"android:exported="true"><intent-filter><action android:name="android.net.conn.CONNECTIVITY_CHANGE" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></receiver><receiverandroid:name="com.xiaomi.push.service.receivers.PingReceiver"android:exported="false"android:process=":pushservice"><intent-filter><action android:name="com.xiaomi.push.PING_TIMER" /></intent-filter></receiver> <!-- 配置小米必须的组件 end --><!-- 配置JPush接受的小米sdk的消息接受类 start --><!--
<receiverandroid:name="cn.jpush.android.service.PluginXiaomiPlatformsReceiver"android:exported="true"><intent-filter><action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" /></intent-filter><intent-filter><action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" /></intent-filter><intent-filter><action android:name="com.xiaomi.mipush.ERROR" /></intent-filter></receiver>--><receiverandroid:name=".message.XMPushReceiver"android:exported="true"><intent-filter><action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" /></intent-filter><intent-filter><action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" /></intent-filter><intent-filter><action android:name="com.xiaomi.mipush.ERROR" /></intent-filter></receiver> <!-- 配置JPush接受的小米sdk的消息接受类 end --><meta-dataandroid:name="XIAOMI_APPKEY"android:value="MI-*********" /><meta-dataandroid:name="XIAOMI_APPID"android:value="MI-*********" /><!--<serviceandroid:name="cn.jpush.android.service.PluginHuaweiPlatformsService"android:exported="false"><intent-filter><action android:name="com.huawei.push.action.MESSAGING_EVENT" /></intent-filter></service>--><serviceandroid:name=".message.HWPushService"android:exported="false"><intent-filter><action android:name="com.huawei.push.action.MESSAGING_EVENT" /></intent-filter></service><receiver android:name="cn.jpush.android.service.PluginVivoMessageReceiver"><intent-filter><!-- 接收 push 消息 --><action android:name="com.vivo.pushclient.action.RECEIVE" /></intent-filter></receiver><serviceandroid:name="com.vivo.push.sdk.service.CommandClientService"android:exported="true" /><activityandroid:name="com.vivo.push.sdk.LinkProxyClientActivity"android:exported="false"android:screenOrientation="portrait"android:theme="@android:style/Theme.Translucent.NoTitleBar" /><meta-dataandroid:name="com.vivo.push.api_key"android:value="***********" /><meta-dataandroid:name="com.vivo.push.app_id"android:value="*********" /> <!-- since JPushv3.6.8 ,oppov2.1.0 oppo 核心功能 --><serviceandroid:name="cn.jpush.android.service.PluginOppoPushService"android:permission="com.coloros.mcs.permission.SEND_MCS_MESSAGE"><intent-filter><action android:name="com.coloros.mcs.action.RECEIVE_MCS_MESSAGE" /></intent-filter></service> <!-- since JPushv3.6.8 ,oppov2.1.0 oppo 核心功能 --><serviceandroid:name="com.heytap.msp.push.service.DataMessageCallbackService"android:permission="com.heytap.mcs.permission.SEND_PUSH_MESSAGE"><intent-filter><action android:name="com.heytap.mcs.action.RECEIVE_MCS_MESSAGE" /><action android:name="com.heytap.msp.push.RECEIVE_MCS_MESSAGE" /></intent-filter></service> <!-- 兼容Q版本 --><meta-dataandroid:name="OPPO_APPKEY"android:value="OP-*********" /><meta-dataandroid:name="OPPO_APPID"android:value="OP-*********" /><meta-dataandroid:name="OPPO_APPSECRET"android:value="OP-*********" />

HWPushService类

public class HWPushService extends HmsMessageService {final PluginHuaweiPlatformsService service = new PluginHuaweiPlatformsService();@Overridepublic void onNewToken(String s) {service.onNewToken(s);Log.d("HWPushService","HWPushService   "+s);}@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {service.onMessageReceived(remoteMessage);Log.d("HWPushService","onMessageReceived");}@Overridepublic void onMessageSent(String s) {service.onMessageSent(s);Log.d("HWPushService","onMessageSent");}@Overridepublic void onSendError(String s, Exception e) {service.onSendError(s,e);Log.d("HWPushService","onSendError");}@Overridepublic void onDeletedMessages() {service.onDeletedMessages();Log.d("HWPushService","onDeletedMessages");}
}
XMPushReceiver类
public class XMPushReceiver extends PushMessageReceiver {final PluginXiaomiPlatformsReceiver receiver = new PluginXiaomiPlatformsReceiver();@Overridepublic void onReceivePassThroughMessage(final Context context, final MiPushMessage message) {Log.d("Jpush", "onReceivePassThroughMessage");// receiver.onReceivePassThroughMessage(context, message);}@Overridepublic void onNotificationMessageClicked(Context context, MiPushMessage message) {// receiver.onNotificationMessageClicked(context, message);Log.d("Jpush", "onNotificationMessageClicked");}@Overridepublic void onNotificationMessageArrived(Context context, MiPushMessage message) {Log.d("Jpush", "onNotificationMessageArrived" + "   message=" + message.toString());// receiver.onNotificationMessageArrived(context, message);//   message(context,message);}@Overridepublic void onCommandResult(Context context, MiPushCommandMessage message) {Log.d("Jpush", "onCommandResult");//   receiver.onCommandResult(context, message);}@Overridepublic void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {// receiver.onReceiveRegisterResult(context, message);Log.d("Jpush", "onReceiveRegisterResult");}

}

OpenClickActivity 点击通知打开的Activity

public class OpenClickActivity extends Activity {private static final String TAG = "OpenClickActivity";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_open_click);Log.d(TAG, "用户点击打开了通知");//handleOpenClick();try {String data = null;//获取华为平台附带的jpush信息if (getIntent().getData() != null) {data = getIntent().getData().toString();}//获取fcm、oppo、vivo、华硕、小米平台附带的jpush信息if (TextUtils.isEmpty(data) && getIntent().getExtras() != null) {data = getIntent().getExtras().getString("JMessageExtra");}if (TextUtils.isEmpty(data)) return;//进程被被杀死,走厂商通道点击通知,会走到这里,先跳转到主页,在主页根据通知的类型,选择跳转的页面;//也可以在这里就判断需要跳转的页面MainActivity.start(OpenClickActivity.this, data);finish();} catch (Exception e) {e.printStackTrace();//如果有错误,友盟上报错误信息到友盟后台if (null != e) {MobclickAgent.reportError(OpenClickActivity.this, " errInfo:"+ e.getLocalizedMessage());}}}

2.5 在build.gradle中配置在华为后台添加的指纹证书对应的签名

    signingConfigs {release {storeFile file("release.keystore")//签名文件的pathstorePassword "123456"keyAlias "android.keystore"keyPassword "123456"}}buildTypes {release {minifyEnabled trueproguardFiles 'proguard-rules.pro'signingConfig signingConfigs.release}debug{minifyEnabled falsesigningConfig signingConfigs.release}}

2.6 混淆

2.6.1 华为

      -ignorewarning -keepattributes *Annotation* -keepattributes Exceptions -keepattributes InnerClasses -keepattributes Signature -keepattributes SourceFile,LineNumberTable -keep class com.hianalytics.android.**{*;} -keep class com.huawei.updatesdk.**{*;} -keep class com.huawei.hms.**{*;}

如果开发者使用了AndResGuard,需要在混淆配置文件中加入AndResGuard白名单。

      "R.string.hms*","R.string.connect_server_fail_prompt_toast","R.string.getting_message_fail_prompt_toast","R.string.no_available_network_prompt_toast","R.string.third_app_*","R.string.upsdk_*","R.layout.hms*","R.layout.upsdk_*","R.drawable.upsdk*","R.color.upsdk*","R.dimen.upsdk*","R.style.upsdk*","R.string.agc*"

2.6.2 小米

-dontwarn com.xiaomi.push.**
-keep class com.xiaomi.push.** { *; }

2.6.3 oppo

-dontwarn com.coloros.mcsdk.**
-keep class com.coloros.mcsdk.** { *; }-dontwarn com.heytap.**
-keep class com.heytap.** { *; }-dontwarn com.mcs.**
-keep class com.mcs.** { *; }

2.6.4 vivo

3 运行程序测试

3.1 进程存活的时候,走的是极光通道

 3.2 杀死进程或者程序没有运行的时候,走的是厂商通道(极光先发送给厂商,厂商发送到具体的手机,在手机对应的平台的推送记录里可以看到)

 这里手机是小米,在小米的推送记录里可以看到

杀死进程后,也能收到通知,通知栏也有通知显示

Android接入极光推送,接入华为,小米,OPPO,VIVO厂商通道相关推荐

  1. android极光推送 小米,android 接极光推送厂商通道,华为 小米 VIVO OPPO

    我首先接入极光推送,然后才来接厂商通道, 需要先接极光推送的看我另外一边帖子, 1   在根目录的build.gradle buildscript{ repositories{ google() jc ...

  2. 海外APP推送(下篇):海外厂商通道集成指南

    作者:极光高级工程师--史坤坤 上篇回顾 上篇我们分享了海外各个厂商的推送通道与FCM通道的对比,了解了厂商通道的优势.那么下面我们手把手教你如何集成海外厂商通道. APP集成海外厂商通道攻略 了解了 ...

  3. Android vivo手机接入极光推送闪退

    最近项目中用到推送功能,选择接入极光推送,可是根据官方文档接入之后,app一启动过一会就闪退,而且是必闪退,翻来覆去看了几遍文档,没有遗漏都开始怀疑人生了. 然后定位问题,把极光推送初始化方法注释就不 ...

  4. uni-app打包安卓app如何接入极光推送(JG-JPush)?

    最近公司在做uni-app的跨端应用,其中在打包app时需要用到消息推送功能,经过一番摸索也是终于弄通并成功集成了第三方极光推送.话不多说,直接开撸: 一.我们需要用到的一些插件以及极光平台的官网链接 ...

  5. Android集成极光推送和踩过的坑(一)

    转载请标明出处 http://blog.csdn.net/mohan6/article/details/72960346 本文作者:[默寒的博客] 集成步骤以及集成过程遇到的坑: 这部分主要阐述了集成 ...

  6. Android集成极光推送踩坑(二)升级篇

    转载请标明出处 http://blog.csdn.net/mohan6/article/details/74133186 本文作者:[默寒的博客] 前言 前段时间针对集成极光推送写了篇文章( Andr ...

  7. 4个顶级的华为/小米/OPPO/Vivo手机屏幕解锁工具软件

    有好几次用户发现自己被锁定在他们的华为/小米/OPPO/Vivo设备之外,我们知道这可能是一种非常可怕的体验.在这种情况下,找到安卓手机解锁软件,重新获得手机中重要数据和文件的访问权限.看看这篇文章, ...

  8. Android华为推送踩坑,极光推送集成华为遇到的坑?

    一.前言: 首先极光推送对各个厂商通道对接是没有在开发者平台提供文档的,需要申请VIP资格后,极光才会提供对应对接文档. 1.极光普通集成 1.步骤1 图片.png 2.步骤2 图片.png 3.步骤 ...

  9. 极光推送接入-客户端

    最近看了看客户端推送,本想着自己实现的,但是任务量还真不小,所以就想着使用现成的,还好极光推送并不收费,让我这个穷逼开心了. 那个三分钟接入的demo基本没什么问题,就是用eclipse export ...

最新文章

  1. 精心总结 Python『八宗罪』,邀你来吐槽
  2. Google 出品的 Java 编码规范,权威又科学,强烈推荐
  3. html5包含哪些知识,HTML5新知识
  4. Linux !的使用
  5. dbscan算法c语言实现,用C++实现DBSCAN聚类算法
  6. Opencv打印显示Mat方法
  7. servlet中文乱码_Servlet入门 信息过滤
  8. 官网MySQL下载速度慢的解决方法(5分钟内搞定)
  9. php 警告和错误屏蔽
  10. RabbitMQ 功能
  11. VirtualBox中安装Android-x86详解
  12. live2d模型二次开发
  13. IEC104规约调试
  14. Java 基本数据类型总结
  15. 服务器装系统报0x0000005d,安装Win8系统提示Error Code:0x0000005D错误怎么办
  16. 11 OPENVINO intermediate course experiment 3 增加性别和年龄识别
  17. Python爬取王者荣耀全皮肤台词语音
  18. Wandb——Pytorch模型指标可视化及超参搜索
  19. 电位器和编码器的区别
  20. mysql 存储过程 varchar 赋值,mysql 存储过程中变量的定义与赋值操作

热门文章

  1. apkrenamer_不怕应用名字乱 在手机端轻松给APK重命名
  2. 【简单远程控制】 Metasploit应用
  3. SVAC的重要Feature
  4. ESP8266/ESP32/nodeMcu/wemos D1 MINI开发板用TFT_eSPI库驱动ST7789(240*240)TFT显示屏
  5. 怎么修改数据库服务器名字,修改SQL Server数据库服务器名字
  6. 解决报错:OSError: Failed to open file b‘D:\\\xe5\xad\xa6\xe4\xb9\xa0\\scipy-_7cm39vc‘(图文并茂版详细版!!)
  7. 详细解读大数据分析学习路线
  8. 【MP】MybatisPlus教程
  9. 实时数仓 大数据 Hadoop flink kafka
  10. 广州集体户口办理未婚证流程