100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Android错误代码返回 【已解决】JPUSH的回调返回错误代码6012

Android错误代码返回 【已解决】JPUSH的回调返回错误代码6012

时间:2023-10-30 04:35:51

相关推荐

Android错误代码返回 【已解决】JPUSH的回调返回错误代码6012

调试android中的jpush的代码。

发现:

set alias的callback中,返回错误代码6012

所以去搜索:

jpush 6012

找到:6012在JPush服务stop状态下设置了tag或alias3.0.0版本新增的错误码。开发者可根据这个错误码的信息做相关处理或者提示。

所以清楚了:

jpush的android的sdk 是3.0.0之后才增加的错误码。

原因是jpush服务还没启动,结果就去调用了onPause导致的。

另外:

中看到了:

onCreate中

JPushInterface.init(this);

之前有个:

JPushInterface.setDebugMode(true);

所以去加上:JPushInterface.setDebugMode(true);

JPushInterface.init(this);

这样可以获得更多的调试信息

后来发现是:

app启动时,没有启动JPUSH服务,结果就在login时的onPause时去暂停了jpush:@Override

protected void onPause() {

JPushInterface.onPause(this);

super.onPause();

}

所以导致返回报错6012,在没有启动jpush时就去暂停。

其中是看到了jpush输出log中提示:

[ServiceInterface] The service is stopped, it will give up all the actions until you call resumePush method to resume the service.

所以去加上resumePush:@Override

protected void onResume() {

JPushInterface.onResume(this);

JPushInterface.resumePush(this);

super.onResume();

}

其中也看到,已经有了:

JPushInterface.onResume(this);

但貌似没有起到效果。

后来又发现,app用户注销后,结果调用了onPause

-》JPushInterface.onPause(this);

-》关闭了jpush的服务

-》所以此处为了保证逻辑正确,就注释掉这个onPause:@Override

protected void onPause() {

//if (!JPushInterface.isPushStopped(this)) {

//JPushInterface.onPause(this);

//}

super.onPause();

}

因为消息推送逻辑应该是:当用户登录成功后,启动jpushsetAlias或setTag

但用户注销(成功)后,,关闭jpush清除alias或tag

然后继续调试发现此处app:用户注销时,是调用关闭jpush服务了JPushInterface.stopPush(SellCarApplication.getAppContext());

但是用户重新登录时,却没有再去开启jpush服务所以自己去加上:

JPushInterface.resumePush(LoginActivity.this);

调试期间的log是:11-10 18:58:08.350 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JPush: [JPushInterface] action:init – sdkVersion:3.0.0, buildId:316

11-10 18:58:08.391 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JPush: [AndroidUtil] action:checkValidManifest

11-10 18:58:08.681 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JPush: [ServiceInterface] The service is stopped, it will give up all the actions until you call resumePush method to resume the service.

11-10 18:58:09.010 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JPush: [JPushInterface] action:resumePush

11-10 18:58:09.159 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JCore: [PushService] onStartCommand – intent:Intent { act=run.action cmp=com.chumi.sellcar.stress/cn.jpush.android.service.PushService (has extras) }, pkg:com.chumi.sellcar.stress, connection:0

11-10 18:58:09.163 9426-9788/com.chumi.sellcar.stress D/JIGUANG-JCore: [ARunAction] Bundle[{action=cn.jpush.android.intent.REPORT, report.extra.info=, report=crash_log, sdktype=JCORE}]

11-10 18:58:09.166 1479-2672/? W/WakePathChecker: MIUILOG-WAKEPATH: call was rejected by wakepath. userId= 0 caller= com.chumi.sellcar.stress callee= com.hupu.games classname=cn.jpush.android.service.DaemonService action=null wakeType=8

11-10 18:58:09.192 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JCore: [PushService] onStartCommand – intent:Intent { act=cn.jpush.android.intent.RESTOREPUSH cmp=com.chumi.sellcar.stress/cn.jpush.android.service.PushService (has extras) }, pkg:com.chumi.sellcar.stress, connection:0

11-10 18:58:09.206 9426-9788/com.chumi.sellcar.stress D/JIGUANG-JPush: [JPushDataAction] Action – onActionRun

11-10 18:58:09.230 9426-9788/com.chumi.sellcar.stress D/JIGUANG-JPush: [PushServiceCore] bundle:Bundle[{action=cn.jpush.android.intent.RESTOREPUSH, app=com.chumi.sellcar.stress, sdktype=JPUSH}]

11-10 18:58:09.231 9426-9788/com.chumi.sellcar.stress D/JIGUANG-JPush: [PushServiceCore] Action – handleServiceAction – action:cn.jpush.android.intent.RESTOREPUSH

11-10 18:58:09.322 9426-9811/com.chumi.sellcar.stress D/JIGUANG-JCore: [ConnectingHelper] To get sis – host:, port:19000, selection:0

11-10 18:58:09.389 9426-9811/com.chumi.sellcar.stress I/JIGUANG-JCore: [ConnectingHelper] Get sis info succeed with host:

11-10 18:58:10.796 9426-9426/com.chumi.sellcar.stress D/JPush: [MyReceiver] onReceive – cn.jpush.android.intent.CONNECTION, extras:

key:cn.jpush.android.APPKEY, value:74e686ba55ab5b0b3a5a1468

key:cn.jpush.android.CONNECTION_CHANGE, value:true

11-10 18:58:10.796 9426-9426/com.chumi.sellcar.stress W/JPush: [MyReceiver]cn.jpush.android.intent.CONNECTION connected state change to true

11-10 18:58:15.927 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JPush: [JPushInterface] action:resumePush

11-10 18:58:15.928 9426-9426/com.chumi.sellcar.stress D/JIGUANG-JPush: [ServiceInterface] service is running already

11-10 18:58:16.084 9426-9426/com.chumi.sellcar.stress D/JPush: Set alias in handler.

。。。

事后:

觉得JPushInterface的那个onResume 很是诡异。

所以去搜搜看看:

JPushInterface onResume

JPushInterface onResume resumePush

【总结】

此处是app代码内部逻辑比较混乱导致jpush没有启动,所以收不到推送。

所以在还没启动时就调用stopPush导致触发6012错误。

去改动对应代码,即可。

总体逻辑参考:API – init

API – stopPush

API – resumePush

API – isPushStopped

所以,写代码其时,要注意在合适的时机触发对应的功能

1.最开始初始化是调用init

2.用户登录(服务器)成功后,调用resumePush -》确保jpush服务开启

3.用户注销退出登录(成功)后,调用stopPush -》确保关闭jpush服务,不再收到推送

为了更加安全,在调用stopPush之前,可以去用isPushStopped判断:如果已停止,可以不调用stopPush

如果正在运行,再调用stopPush去停止

4.用户再次登录(成功)后,调用resumePush -》确保jpush服务重新开启

另外,建议去确认自己所用的jpush的sdk是最新版本,如果不是最新,建议升级到最新。

jpush官网:

-》

当前是3.0.9:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。