第一步,首先看官网文档啊
1. 添加jar MiPush_SDK_Client_3_6_2.jar 到 libs 创建应用就不多说了,记得注册推送时,更改的appid与appkey
在modlue 里 AndroidManifest.xml 添加权限与服务
还需要一个自定义的Receiver
public class DemoMessageReceiver extends PushMessageReceiver {
private String mRegId;
private long mResultCode = -1;
private String mReason;
private String mCommand;
private String mMessage;
private String mTopic;
private String mAlias;
private String mUserAccount;
private String mStartTime;
private String mEndTime;
@Override
public void onReceivePassThroughMessage(Context context, MiPushMessage message) {
mMessage = message.getContent();
if(!TextUtils.isEmpty(message.getTopic())) {
mTopic=message.getTopic();
} else if(!TextUtils.isEmpty(message.getAlias())) {
mAlias=message.getAlias();
} else if(!TextUtils.isEmpty(message.getUserAccount())) {
mUserAccount=message.getUserAccount();
}
}
@Override
public void onNotificationMessageClicked(Context context, MiPushMessage message) {
mMessage = message.getContent();
if(!TextUtils.isEmpty(message.getTopic())) {
mTopic=message.getTopic();
} else if(!TextUtils.isEmpty(message.getAlias())) {
mAlias=message.getAlias();
} else if(!TextUtils.isEmpty(message.getUserAccount())) {
mUserAccount=message.getUserAccount();
}
}
@Override
public void onNotificationMessageArrived(Context context, MiPushMessage message) {
mMessage = message.getContent();
if(!TextUtils.isEmpty(message.getTopic())) {
mTopic=message.getTopic();
} else if(!TextUtils.isEmpty(message.getAlias())) {
mAlias=message.getAlias();
} else if(!TextUtils.isEmpty(message.getUserAccount())) {
mUserAccount=message.getUserAccount();
}
}
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
String command = message.getCommand();
List arguments = message.getCommandArguments();
String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
if (MiPushClient.COMMAND_REGISTER.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mRegId = cmdArg1;
}
} else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mAlias = cmdArg1;
}
} else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mAlias = cmdArg1;
}
} else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mTopic = cmdArg1;
}
} else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mTopic = cmdArg1;
}
} else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mStartTime = cmdArg1;
mEndTime = cmdArg2;
}
}
}
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
String command = message.getCommand();
List arguments = message.getCommandArguments();
String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
if (MiPushClient.COMMAND_REGISTER.equals(command)) {
if (message.getResultCode() == ErrorCode.SUCCESS) {
mRegId = cmdArg1;
}
}
}
}
混淆配置
onNotificationMessageClicked 通知栏点击事件
(该方法必须是服务器端未设置 参数为跳转 extra(Constants.EXTRA_PARAM_NOTIFY_EFFECT,Constants.NOTIFY_ACTIVITY)或者extra(Constants.EXTRA_PARAM_NOTIFY_EFFECT,NOTIFY_LAUNCHER_ACTIVITY);
如果使用以上两种方法,可以使用在跳转至的页面使用getInent()接收
onNotificationMessageArrived 通知送达就会调用该方法