个推号称3分钟让用户无缝介入,然后在我实际对个推精简版介入的耗时确实没有3分钟,各种666的,but在最后调试的出现了问题,能接受到数据,但是通知栏就是弹不出来,老衲十分的困惑,于是对比了官方demo和自己apk的区别(官方demo可以弹出来),透传没有问题,消息推送接受没有问题,那么问题只能出现在通知栏开关上面了,打开之后,果然成功弹出来通知栏。
推送分为 消息推送 , 消息透传 和links信息,下面为名词解释
http://docs.getui.com/getui/more/word/
当你的apk进程被后台杀死之后,相当于你的推送已经掉线了 这时候你是接不到推送的
附上检查推送开关是否打开的代码和链接 运用的是反射原理
https://blog.youkuaiyun.com/androidforwell/article/details/53696433#
为方便本人下次的使用,把精简版的代码给走一遍:
<!--记着添加maven仓库-->
maven {
url "http://mvn.gt.igexin.com/nexus/content/repositories/releases/"
}
PushManager.getInstance().initialize(this.getApplicationContext(), PushService.class);//打开个推核心sdk服务
PushManager.getInstance().stopService(this.getApplicationContext());//关闭个推 核心sdk服务
PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), IntentService.class);//打开个推自定义服务,用来接收消息和服务
PushManager.getInstance().setSilentTime(context, beginHour, durationHour);//设置静默时间 true 设置成功
精简版build.gradle配置
manifestPlaceholders = [
GETUI_APP_ID : "你自己的",
GETUI_APP_KEY : "你自己的",
GETUI_APP_SECRET : "你自己的"
<!--记着添加你自己混淆文件-->
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
<!--记着添加compile -->
compile 'com.getui:sdk:2.12.5.0'
<!-- 配置SDK核心服务 -->
public class PushService extends Service {
@Override
public void onCreate() {
super.onCreate();
GTServiceManager.getInstance().onCreate(this);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return GTServiceManager.getInstance().onStartCommand(this, intent, flags, startId);
}
@Override
public IBinder onBind(Intent intent) {
return GTServiceManager.getInstance().onBind(intent);
}
@Override
public void onDestroy() {
super.onDestroy();
GTServiceManager.getInstance().onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
GTServiceManager.getInstance().onLowMemory();
}
}
<!-- 用户自定义服务继承自GTIntentService,作为SDK与APP桥梁服务,用来接收各种消息和命令回复-->
public class IntentService extends GTIntentService {
@Override
public void onReceiveServicePid(Context context, int i) {
//获取pid
}
@Override
public void onReceiveClientId(Context context, String s) {
//获取ClientId = s
}
@Override
public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
//获取透传消息
}
@Override
public void onReceiveOnlineState(Context context, boolean b) {
//获取在线状态
}
@Override
public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {
}
@Override
public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {
//推送栏回调
}
@Override
public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {
通知栏点击
}
}