只是为了记录怎么用,官网申请id啥的不说的.直接上代码.
1 清单文件中: 加入权限:
然后加入申明:
极光大概要这几个类:
文章图片
2 代码中: 在application中就加入这两句:
JPushInterface.setDebugMode(true);
JPushInterface.init(getApplication());
【简单接入极光推送】在MainActivity中加入下面代码:
public void registerMessageReceiver() {
mMessageReceiver = new MessageReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(MESSAGE_RECEIVED_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter);
}private static class MessageReceiver extends BroadcastReceiver {@Override
public void onReceive(Context context, Intent intent) {
try {
if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {
String messge = intent.getStringExtra(KEY_MESSAGE);
String extras = intent.getStringExtra(KEY_EXTRAS);
StringBuilder showMsg = new StringBuilder();
showMsg.append(KEY_MESSAGE + " : " + messge + "\n");
if (!ExampleUtil.isEmpty(extras)) {
showMsg.append(KEY_EXTRAS + " : " + extras + "\n");
}
ToastUtils.showToast(showMsg.toString());
}
} catch (Exception e) {
}
}
}@Override
protected void onResume() {
isForeground = true;
super.onResume();
}@Override
protected void onPause() {
isForeground = false;
super.onPause();
}
完成! 里面的代码已经上传:代码