Android 极光推送
步骤
步骤:
1, 注册,登录成为开发者。 官方网站:https://www.jiguang.cn
2, 在控制台创建应用: 参考链接:https://www.jiguang.cn/dev/#/app/list#dev
3, 设置包名。包名一定和应用程序包名一致
4, 生成对应的AppKey
5, 集成sdk 使用jcenter自动集成
https://docs.jiguang.cn//jpush/client/Android/android_guide/#jcenter
6, 定义一个Application类,在oncreate里调用。
JPushInterface.setDebugMode(true);//调试模式。
JPushInterface.init(this);
7, 在AndroidManifest.xml里, 添加 Application。
8, 定义一个receiver例如MyReceiver, 继承 BroadcastReceiver,并重写onReceiver函数。
9, 在AndroidManifest中注册MyReceiver。注意包名别忘了写。
10, 在MyReceiver里接收信息。
参考链接:https://docs.jiguang.cn//jpush/client/Android/android_api/#receiver
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() ==
JPushInterface.ACTION_MESSAGE_RECEIVED) {
Bundle bundle = intent.getExtras();
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);//读取自定义信息内容
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); //读取自定义信息附加字段, 是一个json字符串。
String value = null;
try {
JSONObject jsonObject = new JSONObject(extras);
value = (String) jsonObject.get("class"); //读取附件字段class的value值.
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("onReceive:", "ACTION_MESSAGE_RECEIVED::" + message);
} else if (intent.getAction() == JPushInterface.ACTION_NOTIFICATION_RECEIVED) {
Log.d("onReceive:", "ACTION_NOTIFICATION_RECEIVED");
Bundle bundle = intent.getExtras();
String content = bundle.getString(JPushInterface.EXTRA_ALERT); //读取通知内容
Log.d("onReceive:", "ACTION_MESSAGE_RECEIVED::" + content);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); //读取自定义信息附加字段, 是一个json字符串。
String value = null;
try {
JSONObject jsonObject = new JSONObject(extras);
value = (String) jsonObject.get("class"); //读取附件字段class的value值.
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
11, 控制台发送自定义信息:
12, 控制台发送通知:
https://mob.com/ 第三方分享