极光推送 JPush 简介 集成

JPush产品简介


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

主要功能:
  • 保持与服务器的长连接,以便消息能够即时推送到达客户端
  • 接收通知与自定义消息,并向开发者App传递相关信息

主要特点:
  • 客户端维持连接占用资源少、耗电低
  • SDK丰富的接口,可定制通知栏提示样式
  • 服务器大容量、稳定

原理: JPush Android SDK 是作为 Android Service 长期运行在后台的,从而创建并保持长连接,保持永远在线的能力。

JPush是经过考验的大规模APP推送平台,每天推送消息数超过5亿条。 开发者集成SDK后,可以通过调用API推送消息。同时,JPush提供可视化的web端控制台发送通知,统计分析推送效果。 JPush全面支持 Android, iOS, Winphone 三大手机平台。


消息形式

JPush提供四种消息形式:通知,自定义消息,富媒体和本地通知。

795730-20180418134022034-1810256371.jpg
1、通知

或者说 Push Notification,即指在手机的通知栏(状态栏)上会显示的一条通知信息。 通知主要用于提示用户的目的,应用于新闻内容、促销活动、产品信息、版本更新提醒、订单状态提醒等多种场景

开发者参考文档:Push API v3 notification


2、自定义消息

自定义消息不是通知,所以不会被SDK展示到通知栏上。其内容完全由开发者自己定义。 自定义消息主要用于应用的内部业务逻辑。一条自定义消息推送过来,有可能没有任何界面显示。

开发者参考文档:Push API v3 message


3、富媒体

JPush支持开发者发送图文并茂的通知,从而更好的传达信息,带来更丰富的用户互动。 JPush提供了5种模板,开发者可以通过填充模板的内容,发送landing page、弹窗、信息流形式的富媒体通知。 开发者还可以直接通过URL发送预先编辑好的页面。 富媒体当前支持Android平台,为更好的使用富媒体的功能,建议更新当前SDK版本至v2.1.8及以上。 暂时只能通过极光推送的控制台发送,不支持API形式。

Android 开发者参考文档:Rich Push开发指南


4、本地通知

本地通知API不依赖于网络,无网条件下依旧可以触发;本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响。 本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制。 本地通知适用于在特定时间发出的通知,如一些Todo和闹钟类的应用,在每周、每月固定时间提醒用户回到应用查看任务。

Android 开发者参考文档:Android 本地通知 iOS 开发者参考文档:iOS 本地通知


推送目标

通过使用标签,别名,Registration ID 和用户分群,开发者可以向特定的一个或多个用户推送消息。


1、标签

为安装了应用程序的用户打上标签,其目的主要是方便开发者根据标签,来批量下发 Push 消息。 可为每个用户打多个标签。 举例: game, old_page, women


2、别名

每个用户只能指定一个别名(意思是说,一个别名可以有多个用户)。 同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。

Android 开发者参考文档:Android 标签和别名 iOS 开发者参考文档:iOS 标签和别名 使用别名和标签推送请参考文档:Push API v3 Audience


3、Registration ID

客户端初始化 JPush 成功后,JPush 服务端会分配一个 Registration ID,作为此设备的标识(同一个手机不同 APP 的 Registration ID 是不同的)。开发者可以通过指定具体的 Registration ID 来进行对单一设备的推送。


4、用户分群

用户分群的筛选条件有:标签、地理位置、系统版本、注册时间、活跃用户和在线用户。 比如,开发者可以设置这样的用户分群:位于北京、上海、广州和深圳,并且最近7天在线的用户。 开发者可以通过在控制台设置好用户分群之后,在控制台推送时指定该分群的名称或使用API调用该分群的id发送。

用户分群控制台使用指南:用户分群


5、统计分析

JPush支持推送数量、用户打开次数、用户使用时长、新增用户、活跃用户等数据的统计。 Android开发者需要实现了相关的统计API,才可以进行用户相关的统计。 iOS的开发者不需要实现统计API,可以直接在【控制台】-【统计】页面查看相关数据。

Android 开发者参考文档:统计分析API


集成步骤


1、快速开始
  • 到极光推送官方网站注册开发者帐号
  • 登录进入管理控制台,创建应用程序,得到 Appkey(SDK与服务器端通过Appkey互相识别);
  • 下载SDK 集成到 App 里。

2、三 分钟快速使用
  • 1、创建应用
    使用注册账号登陆,进入极光控制台后,点击“创建应用”按钮。创建帐号进入极光推送后,首先显示的是创建应用的界面。填上你的应用程序的名称,以及 Android包名这二项就可以了。
  • 2、下载Demo,导入AS,运行
    点击 ”下载Demo“,你将下载到一个 .zip 压缩文件。解压后,即看到一个同名目录。这个目录下,是一个 Android 项目里的所有文件。
    在 Android Studio 中,新建一个项目。 通过 import module 导入 JPush Example 
    导入 module 后在 Android studio 内运行到指定设备上
  • 3、Portal上推送通知和消息
    在上述步骤安装 JPush Example 的手机上,你就可以收到推送的通知和消息了。

FAQ


怎么样保证推送消息的安全?

我们建议开发者不要推送保密的信息,就像QQ建议你不要在聊天时发送保密的信息一样。
如果开发者的确有保密的信息,需要送达到用户,则可以考虑这样做:
先通过 JPush 推送一条消息,这条消息触发客户端App去与开发者服务器交互保密信息。


极光推送后台使用什么技术实现的?是 XMPP 协议么?

后台主要使用纯 C 语言实现。
使用自定义的二进制协议,以尽可能节约流量。


可以推送多媒体文件到客户端么?

推送消息本身是限定长度的文本。
不直接支持文件的推送,但可以通过推送 url 来实现。
即先推送文件下载 url,到客户端触发逻辑来通过 url 下载文件。


为什么应用程序无法收到 Push 消息(Android)?
确认 appKey(在Portal上生成的)已经正确的写入 Androidmanifest.xml
确认测试手机(或者模拟器)已成功连入网络
确认有客户端 "Login succeed" 日志

日志:Java.lang.UnsatisfiedLinkError
此错误是由于没有正确的加载libjpush.so文件,请检查libjpush.so是否在正确的位置(libs–>armeabi–>libjpush.so)
JPush SDK 迁移到 Android Studio 需要添加 .SO 文件打包到APK的lib文件夹中,可以编辑 build.gradle 脚本,自定义 *.so 目录。

日志:The permission should be defined
此错误是没有正确的定义permision,请添加权限:
<permission android:name="您应用的包名.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="您应用的包名.permission.JPUSH_MESSAGE" />
2
2
 
1
<permission android:name="您应用的包名.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
2
<uses-permission android:name="您应用的包名.permission.JPUSH_MESSAGE" />


推送成功了,为什么有部分客户端收不到推送?
请检查收不到通知的手机:
请在logcat查看日志,确定客户端的jpush是否集成成功,网络是否有问题
请看日志或使用接口 isPushStopped来检查是否调用了stoppush
检查手机的JPush高级设置中是否设置了“允许推送时间”
手机的应用中是否勾选了“显示通知”

Tag、Alias、Registrationid需要每次初始化时都重新设置吗,会变化吗?
tag、alias可以参考别名与标签 API进行设置, 每次设置是覆盖设置,而不是增量设置。 Tag和alias一经设置成功,除非取消或覆盖,是不会变化的。设置好的tag、alias与客户端的对应关系保存在JPush服务器,目前没有从JPush服务器查询这个对应关系的接口,所以需要客户将对应关系保存在APP应用服务器。
Registrationid是客户端SDK第一次成功连接到Jpush服务器时,Jpush服务器给分配的。可以通过获取 RegistrationID API来获取Registrationid进行推送。Registrationid对应一个应用的一个客户端。

appkey是怎么对应的?
android 的包名和 appkey 需对应。

简洁版自定义消息推送Demo

自定义消息又叫应用内消息,或者称作 透传消息。 此部分内容不会展示到通知栏上,JPush SDK 收到消息内容后透传给 App,需要 App 自行处理。
关键字类型选项含义
msg_contentstring必填消息内容本身
titlestring可选消息标题
content_typestring可选消息内容类型
extrasJSON Object可选JSON 格式的可选参数
在适当的时候初始化
JPushInterface.setDebugMode(true);    // 设置开启日志,发布时请关闭日志
JPushInterface.init(this);            // 初始化 JPush
x
9
 
1
JPushInterface.setDebugMode(true);    // 设置开启日志,发布时请关闭日志
2
JPushInterface.init(this);            // 初始化 JPush

Activity

public class JpushMainActivity extends ListActivity {
	
	public static boolean isForeground = false;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		TextView tv = new TextView(this);
		tv.setTextColor(Color.BLUE);
		String string = "AppKey: " + PushUtil.getAppKey(this) + "\n" +
				"IMEI: " + PushUtil.getImei(this, "") + "\n" +
				"RegId:" + JPushInterface.getRegistrationID(this) + "\n" +
				"PackageName: " + getPackageName() + "\n" +
				"deviceId:" + PushUtil.getDeviceId(this) + "\n" +
				"Version: " + PushUtil.GetVersionName(this);
		tv.setText(string);
		getListView().addHeaderView(tv);
		
		String[] array = {"initPush", "stopPush", "resumePush",};
		setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new ArrayList<>(Arrays.asList(array))));
		EventBus.getDefault().register(this);
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		switch (position - 1) {
			case 0:
				JPushInterface.init(this);// 初始化 JPush。如果已经初始化,但没有登录成功,则执行重新登录。
				break;
			case 1:
				JPushInterface.stopPush(this);
				break;
			case 2:
				JPushInterface.resumePush(this);
				break;
		}
	}
	
	@Override
	protected void onResume() {
		isForeground = true;
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		isForeground = false;
		super.onPause();
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		EventBus.getDefault().unregister(this);
	}
	
	@Subscribe(threadMode = ThreadMode.MAIN)
	public void onPushEvent(BasePushBean bean) {
		TextView tv = new TextView(this);
		tv.setTextColor(Color.BLUE);
		tv.setText(bean.msg);
		getListView().addFooterView(tv);
	}
}
x
 
1
public class JpushMainActivity extends ListActivity {
2
    
3
    public static boolean isForeground = false;
4
    
5
    protected void onCreate(Bundle savedInstanceState) {
6
        super.onCreate(savedInstanceState);
7
        TextView tv = new TextView(this);
8
        tv.setTextColor(Color.BLUE);
9
        String string = "AppKey: " + PushUtil.getAppKey(this) + "\n" +
10
                "IMEI: " + PushUtil.getImei(this, "") + "\n" +
11
                "RegId:" + JPushInterface.getRegistrationID(this) + "\n" +
12
                "PackageName: " + getPackageName() + "\n" +
13
                "deviceId:" + PushUtil.getDeviceId(this) + "\n" +
14
                "Version: " + PushUtil.GetVersionName(this);
15
        tv.setText(string);
16
        getListView().addHeaderView(tv);
17
        
18
        String[] array = {"initPush", "stopPush", "resumePush",};
19
        setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new ArrayList<>(Arrays.asList(array))));
20
        EventBus.getDefault().register(this);
21
    }
22
    
23
    @Override
24
    protected void onListItemClick(ListView l, View v, int position, long id) {
25
        switch (position - 1) {
26
            case 0:
27
                JPushInterface.init(this);// 初始化 JPush。如果已经初始化,但没有登录成功,则执行重新登录。
28
                break;
29
            case 1:
30
                JPushInterface.stopPush(this);
31
                break;
32
            case 2:
33
                JPushInterface.resumePush(this);
34
                break;
35
        }
36
    }
37
    
38
    @Override
39
    protected void onResume() {
40
        isForeground = true;
41
        super.onResume();
42
    }
43
    
44
    @Override
45
    protected void onPause() {
46
        isForeground = false;
47
        super.onPause();
48
    }
49
    
50
    @Override
51
    protected void onDestroy() {
52
        super.onDestroy();
53
        EventBus.getDefault().unregister(this);
54
    }
55
    
56
    @Subscribe(threadMode = ThreadMode.MAIN)
57
    public void onPushEvent(BasePushBean bean) {
58
        TextView tv = new TextView(this);
59
        tv.setTextColor(Color.BLUE);
60
        tv.setText(bean.msg);
61
        getListView().addFooterView(tv);
62
    }
63
}

Receiver

/**
 * 自定义接收器。如果不定义这个 Receiver,则默认用户会打开主界面,接收不到自定义消息
 */
public class MyReceiver extends BroadcastReceiver {
	
	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent == null || intent.getAction() == null) return;
		
		Bundle bundle = intent.getExtras();
		Log.i("bqt", "【MyReceiver】Action:" + intent.getAction() + "\nextras:" + printBundle(bundle));
		
		switch (intent.getAction()) {
			case JPushInterface.ACTION_REGISTRATION_ID:
				String regId = bundle == null ? "" : bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
				Log.i("bqt", "【MyReceiver】接收Registration Id : " + regId);
				break;
			case JPushInterface.ACTION_MESSAGE_RECEIVED://将自定义消息转发到需要的地方
				Log.i("bqt", "【MyReceiver】接收到推送下来的自定义消息");
				if (JpushMainActivity.isForeground && bundle != null) {
					String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
					String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
					String msg = "message:" + message + "\nextras:" + extras;
					EventBus.getDefault().post(new BasePushBean(msg, BasePushBean.TYPE_STRING));
				}
				break;
			case JPushInterface.ACTION_NOTIFICATION_RECEIVED:
				Log.i("bqt", "【MyReceiver】接收到推送下来的通知");
				int notifactionId = bundle == null ? -1 : bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
				Log.i("bqt", "【MyReceiver】接收到推送下来的通知的ID: " + notifactionId);
				break;
			case JPushInterface.ACTION_NOTIFICATION_OPENED:
				Log.i("bqt", "【MyReceiver】用户点击打开了通知");
				break;
			case JPushInterface.ACTION_RICHPUSH_CALLBACK:  // 根据 JPushInterface.EXTRA_EXTRA 的内容处理代码
				String extra = bundle == null ? "" : bundle.getString(JPushInterface.EXTRA_EXTRA);
				Log.i("bqt", "【MyReceiver】用户收到到RICH PUSH CALLBACK: " + extra);
				break;
			case JPushInterface.ACTION_CONNECTION_CHANGE:
				boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
				Log.i("bqt", "【MyReceiver】" + intent.getAction() + " connected state change to " + connected);
				break;
			default:
				Log.i("bqt", "【MyReceiver】Unhandled intent - " + intent.getAction());
				break;
		}
		
	}
	
	// 打印所有的 intent extra 数据
	private static String printBundle(Bundle bundle) {
		if (bundle == null) return "";
		StringBuilder sb = new StringBuilder();
		for (String key : bundle.keySet()) {
			switch (key) {
				case JPushInterface.EXTRA_NOTIFICATION_ID:
					sb.append("\nkey:").append(key).append(", value:").append(bundle.getInt(key));
					break;
				case JPushInterface.EXTRA_CONNECTION_CHANGE:
					sb.append("\nkey:").append(key).append(", value:").append(bundle.getBoolean(key));
					break;
				case JPushInterface.EXTRA_EXTRA:
					if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
						Log.i("bqt", "This message has no Extra data");
						continue;
					}
					try {
						JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
						Iterator<String> it = json.keys();
						while (it.hasNext()) {
							String myKey = it.next();
							sb.append("\nkey:").append(key)
									.append(", value: [").append(myKey)
									.append(" - ").append(json.optString(myKey)).append("]");
						}
					} catch (JSONException e) {
						Log.e("bqt", "Get message extra JSON error!");
					}
					break;
				default:
					sb.append("\nkey:").append(key).append(", value:").append(bundle.getString(key));
					break;
			}
		}
		return sb.toString();
	}
}
Receiver
x
1
/**
2
 * 自定义接收器。如果不定义这个 Receiver,则默认用户会打开主界面,接收不到自定义消息
3
 */
4
public class MyReceiver extends BroadcastReceiver {
5
    
6
    @Override
7
    public void onReceive(Context context, Intent intent) {
8
        if (intent == null || intent.getAction() == null) return;
9
        
10
        Bundle bundle = intent.getExtras();
11
        Log.i("bqt", "【MyReceiver】Action:" + intent.getAction() + "\nextras:" + printBundle(bundle));
12
        
13
        switch (intent.getAction()) {
14
            case JPushInterface.ACTION_REGISTRATION_ID:
15
                String regId = bundle == null ? "" : bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
16
                Log.i("bqt", "【MyReceiver】接收Registration Id : " + regId);
17
                break;
18
            case JPushInterface.ACTION_MESSAGE_RECEIVED://将自定义消息转发到需要的地方
19
                Log.i("bqt", "【MyReceiver】接收到推送下来的自定义消息");
20
                if (JpushMainActivity.isForeground && bundle != null) {
21
                    String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
22
                    String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
23
                    String msg = "message:" + message + "\nextras:" + extras;
24
                    EventBus.getDefault().post(new BasePushBean(msg, BasePushBean.TYPE_STRING));
25
                }
26
                break;
27
            case JPushInterface.ACTION_NOTIFICATION_RECEIVED:
28
                Log.i("bqt", "【MyReceiver】接收到推送下来的通知");
29
                int notifactionId = bundle == null ? -1 : bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
30
                Log.i("bqt", "【MyReceiver】接收到推送下来的通知的ID: " + notifactionId);
31
                break;
32
            case JPushInterface.ACTION_NOTIFICATION_OPENED:
33
                Log.i("bqt", "【MyReceiver】用户点击打开了通知");
34
                break;
35
            case JPushInterface.ACTION_RICHPUSH_CALLBACK:  // 根据 JPushInterface.EXTRA_EXTRA 的内容处理代码
36
                String extra = bundle == null ? "" : bundle.getString(JPushInterface.EXTRA_EXTRA);
37
                Log.i("bqt", "【MyReceiver】用户收到到RICH PUSH CALLBACK: " + extra);
38
                break;
39
            case JPushInterface.ACTION_CONNECTION_CHANGE:
40
                boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
41
                Log.i("bqt", "【MyReceiver】" + intent.getAction() + " connected state change to " + connected);
42
                break;
43
            default:
44
                Log.i("bqt", "【MyReceiver】Unhandled intent - " + intent.getAction());
45
                break;
46
        }
47
        
48
    }
49
    
50
    // 打印所有的 intent extra 数据
51
    private static String printBundle(Bundle bundle) {
52
        if (bundle == null) return "";
53
        StringBuilder sb = new StringBuilder();
54
        for (String key : bundle.keySet()) {
55
            switch (key) {
56
                case JPushInterface.EXTRA_NOTIFICATION_ID:
57
                    sb.append("\nkey:").append(key).append(", value:").append(bundle.getInt(key));
58
                    break;
59
                case JPushInterface.EXTRA_CONNECTION_CHANGE:
60
                    sb.append("\nkey:").append(key).append(", value:").append(bundle.getBoolean(key));
61
                    break;
62
                case JPushInterface.EXTRA_EXTRA:
63
                    if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
64
                        Log.i("bqt", "This message has no Extra data");
65
                        continue;
66
                    }
67
                    try {
68
                        JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
69
                        Iterator<String> it = json.keys();
70
                        while (it.hasNext()) {
71
                            String myKey = it.next();
72
                            sb.append("\nkey:").append(key)
73
                                    .append(", value: [").append(myKey)
74
                                    .append(" - ").append(json.optString(myKey)).append("]");
75
                        }
76
                    } catch (JSONException e) {
77
                        Log.e("bqt", "Get message extra JSON error!");
78
                    }
79
                    break;
80
                default:
81
                    sb.append("\nkey:").append(key).append(", value:").append(bundle.getString(key));
82
                    break;
83
            }
84
        }
85
        return sb.toString();
86
    }
87
}

配置文件

build.gradle
implementation files('libs/jcore-android-1.2.0.jar')
implementation files('libs/jpush-android-3.1.2.jar')
implementation 'org.greenrobot:eventbus:3.1.1'
x
 
1
implementation files('libs/jcore-android-1.2.0.jar')
2
implementation files('libs/jpush-android-3.1.2.jar')
3
implementation 'org.greenrobot:eventbus:3.1.1'
混淆文件:proguard-android.txt
-dontoptimize
-dontpreverify
-dontwarn cn.jpush.**
-keep class cn.jpush.** { *; }

#v2.0.5 及以上的版本由于引入了protobuf ,在上面基础之上增加排除混淆的配置。
#==================gson==========================
-dontwarn com.google.**
-keep class com.google.gson.** {*;}

#==================protobuf======================
-dontwarn com.google.**
-keep class com.google.protobuf.** {*;}
13
 
1
-dontoptimize
2
-dontpreverify
3
-dontwarn cn.jpush.**
4
-keep class cn.jpush.** { *; }
5
 
          
6
#v2.0.5 及以上的版本由于引入了protobuf ,在上面基础之上增加排除混淆的配置。
7
#==================gson==========================
8
-dontwarn com.google.**
9
-keep class com.google.gson.** {*;}
10
 
          
11
#==================protobuf======================
12
-dontwarn com.google.**
13
-keep class com.google.protobuf.** {*;}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.bqt.push">

    <permission
        android:name="com.bqt.push.permission.JPUSH_MESSAGE"
        android:protectionLevel="signature"/>

    <!-- Required  一些系统要求的权限,如访问网络等-->
    <uses-permission android:name="com.bqt.push.permission.JPUSH_MESSAGE"/>
    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:name=".APP"
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher">

        <activity
            android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        
        <activity android:name=".jpush.JpushMainActivity"/>

        <activity
            android:name="cn.jpush.android.ui.PopWinActivity"
            android:exported="false"
            android:theme="@style/MyDialogStyle">
        </activity>

        <activity
            android:name="cn.jpush.android.ui.PushActivity"
            android:configChanges="orientation|keyboardHidden"
            android:exported="false"
            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="com.bqt.push"/>
            </intent-filter>
        </activity>

        <service
            android:name="cn.jpush.android.service.PushService"
            android:exported="false"
            android:process=":mult">
            <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>

        <provider
            android:name="cn.jpush.android.service.DataProvider"
            android:authorities="com.bqt.push.DataProvider"
            android:exported="false"/>

        <!-- 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
        <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
        <service
            android:name="cn.jpush.android.service.DaemonService"
            android:enabled="true"
            android:exported="true"
            tools:ignore="ExportedService">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.DaemonService"/>
                <category android:name="com.bqt.push"/>
            </intent-filter>
        </service>

        <provider
            android:name="cn.jpush.android.service.DownloadProvider"
            android:authorities="com.bqt.push.DownloadProvider"
            android:exported="true"
            tools:ignore="ExportedContentProvider"/>

        <receiver
            android:name="cn.jpush.android.service.PushReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter android:priority="1000">
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>   <!--Required  显示通知栏 -->
                <category android:name="com.bqt.push"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT"/>
                <action
                    android:name="android.net.conn.CONNECTIVITY_CHANGE"
                    tools:ignore="BatteryLife"/>
            </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>

        <receiver
            android:name="cn.jpush.android.service.AlarmReceiver"
            android:exported="false"/>

        <!-- User defined.  用户自定义的广播接收器-->
        <receiver
            android:name="com.bqt.push.jpush.MyReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTRATION"/> <!--Required  用户注册SDK的intent-->
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/> <!--Required  用户接收SDK消息的intent-->
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/> <!--Required  用户接收SDK通知栏信息的intent-->
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/> <!--Required  用户打开自定义通知栏的intent-->
                <action android:name="cn.jpush.android.intent.CONNECTION"/><!-- 接收网络变化 连接/断开 since 1.6.3 -->
                <category android:name="com.bqt.push"/>
            </intent-filter>
        </receiver>

        <!-- Enable it you can get statistics data with channel -->
        <meta-data
            android:name="JPUSH_CHANNEL"
            android:value="developer-default"/>
        <meta-data
            android:name="JPUSH_APPKEY"
            android:value="7ced56a29466cb706362bb82"/> <!-- 值来自开发者平台取得的AppKey-->

    </application>
</manifest>
x
 
1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
          xmlns:tools="http://schemas.android.com/tools"
4
          package="com.bqt.push">
5
 
          
6
    <permission
7
        android:name="com.bqt.push.permission.JPUSH_MESSAGE"
8
        android:protectionLevel="signature"/>
9
 
          
10
    <!-- Required  一些系统要求的权限,如访问网络等-->
11
    <uses-permission android:name="com.bqt.push.permission.JPUSH_MESSAGE"/>
12
    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
13
    <uses-permission android:name="android.permission.INTERNET"/>
14
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
15
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
16
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
17
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
18
    <uses-permission android:name="android.permission.VIBRATE"/>
19
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
20
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
21
 
          
22
    <application
23
        android:name=".APP"
24
        android:allowBackup="false"
25
        android:icon="@drawable/ic_launcher">
26
 
          
27
        <activity
28
            android:name=".MainActivity">
29
            <intent-filter>
30
                <action android:name="android.intent.action.MAIN"/>
31
                <category android:name="android.intent.category.LAUNCHER"/>
32
            </intent-filter>
33
        </activity>
34
        
35
        <activity android:name=".jpush.JpushMainActivity"/>
36
 
          
37
        <activity
38
            android:name="cn.jpush.android.ui.PopWinActivity"
39
            android:exported="false"
40
            android:theme="@style/MyDialogStyle">
41
        </activity>
42
 
          
43
        <activity
44
            android:name="cn.jpush.android.ui.PushActivity"
45
            android:configChanges="orientation|keyboardHidden"
46
            android:exported="false"
47
            android:theme="@android:style/Theme.NoTitleBar">
48
            <intent-filter>
49
                <action android:name="cn.jpush.android.ui.PushActivity"/>
50
 
          
51
                <category android:name="android.intent.category.DEFAULT"/>
52
                <category android:name="com.bqt.push"/>
53
            </intent-filter>
54
        </activity>
55
 
          
56
        <service
57
            android:name="cn.jpush.android.service.PushService"
58
            android:exported="false"
59
            android:process=":mult">
60
            <intent-filter>
61
                <action android:name="cn.jpush.android.intent.REGISTER"/>
62
                <action android:name="cn.jpush.android.intent.REPORT"/>
63
                <action android:name="cn.jpush.android.intent.PushService"/>
64
                <action android:name="cn.jpush.android.intent.PUSH_TIME"/>
65
            </intent-filter>
66
        </service>
67
 
          
68
        <provider
69
            android:name="cn.jpush.android.service.DataProvider"
70
            android:authorities="com.bqt.push.DataProvider"
71
            android:exported="false"/>
72
 
          
73
        <!-- 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
74
        <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
75
        <service
76
            android:name="cn.jpush.android.service.DaemonService"
77
            android:enabled="true"
78
            android:exported="true"
79
            tools:ignore="ExportedService">
80
            <intent-filter>
81
                <action android:name="cn.jpush.android.intent.DaemonService"/>
82
                <category android:name="com.bqt.push"/>
83
            </intent-filter>
84
        </service>
85
 
          
86
        <provider
87
            android:name="cn.jpush.android.service.DownloadProvider"
88
            android:authorities="com.bqt.push.DownloadProvider"
89
            android:exported="true"
90
            tools:ignore="ExportedContentProvider"/>
91
 
          
92
        <receiver
93
            android:name="cn.jpush.android.service.PushReceiver"
94
            android:enabled="true"
95
            android:exported="false">
96
            <intent-filter android:priority="1000">
97
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>   <!--Required  显示通知栏 -->
98
                <category android:name="com.bqt.push"/>
99
            </intent-filter>
100
            <intent-filter>
101
                <action android:name="android.intent.action.USER_PRESENT"/>
102
                <action
103
                    android:name="android.net.conn.CONNECTIVITY_CHANGE"
104
                    tools:ignore="BatteryLife"/>
105
            </intent-filter>
106
            <!-- Optional -->
107
            <intent-filter>
108
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
109
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
110
 
          
111
                <data android:scheme="package"/>
112
            </intent-filter>
113
        </receiver>
114
 
          
115
        <receiver
116
            android:name="cn.jpush.android.service.AlarmReceiver"
117
            android:exported="false"/>
118
 
          
119
        <!-- User defined.  用户自定义的广播接收器-->
120
        <receiver
121
            android:name="com.bqt.push.jpush.MyReceiver"
122
            android:enabled="true"
123
            android:exported="false">
124
            <intent-filter>
125
                <action android:name="cn.jpush.android.intent.REGISTRATION"/> <!--Required  用户注册SDK的intent-->
126
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/> <!--Required  用户接收SDK消息的intent-->
127
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/> <!--Required  用户接收SDK通知栏信息的intent-->
128
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/> <!--Required  用户打开自定义通知栏的intent-->
129
                <action android:name="cn.jpush.android.intent.CONNECTION"/><!-- 接收网络变化 连接/断开 since 1.6.3 -->
130
                <category android:name="com.bqt.push"/>
131
            </intent-filter>
132
        </receiver>
133
 
          
134
        <!-- Enable it you can get statistics data with channel -->
135
        <meta-data
136
            android:name="JPUSH_CHANNEL"
137
            android:value="developer-default"/>
138
        <meta-data
139
            android:name="JPUSH_APPKEY"
140
            android:value="7ced56a29466cb706362bb82"/> <!-- 值来自开发者平台取得的AppKey-->
141
 
          
142
    </application>
143
</manifest>
2018-4-9




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Spring Boot集成极光推送的步骤: 1. 在pom.xml文件中添加极光推送的依赖: ```xml <dependency> <groupId>cn.jiguang</groupId> <artifactId>jpush-spring-boot-starter</artifactId> <version>3.4.0</version> </dependency> ``` 2. 在application.yml或application.properties文件中配置极光推送的相关信息: ```yaml jpush: app-key: f54*******************92 master-secret: d6*****************055 production: true ``` 请注意将上述代码中的app-key和master-secret替换为你自己的极光推送的AppKey和AppSecret。 3. 创建一个推送服务类,用于发送推送消息: ```java import cn.jpush.api.JPushClient; import cn.jpush.api.push.PushResult; import cn.jpush.api.push.model.Message; import cn.jpush.api.push.model.Platform; import cn.jpush.api.push.model.PushPayload; import cn.jpush.api.push.model.audience.Audience; import cn.jpush.api.push.model.notification.Notification; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service public class JPushService { @Value("${jpush.app-key}") private String appKey; @Value("${jpush.master-secret}") private String masterSecret; @Value("${jpush.production}") private boolean production; public void sendPush(String message) { JPushClient jpushClient = new JPushClient(masterSecret, appKey); PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.all()) .setAudience(Audience.all()) .setMessage(Message.content(message)) .build(); try { PushResult result = jpushClient.sendPush(payload); System.out.println("推送结果:" + result); } catch (Exception e) { e.printStackTrace(); } } } ``` 4. 在需要发送推送消息的地方调用推送服务类的sendPush方法: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class PushController { @Autowired private JPushService jPushService; @GetMapping("/push") public String pushMessage() { jPushService.sendPush("这是一条测试推送消息"); return "推送成功"; } } ``` 以上代码演示了如何在Spring Boot中集成极光推送,并发送一条推送消息。你可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值