极光推送设置别名和标签
程序员文章站
2022-06-01 18:58:52
...
做项目需要用,上网看了下文档和博客,自己总结,以后还要用;
3.0.7版本的回调方法
设置别名和标签
通过回调处理返回的数据,6002是超时码,可以进行重连操作
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
super.handleMessage(msg);
if (msg.what == 100) {
JPushInterface.setAlias(getApplicationContext(), TAG, alias);
}
}
};
private JPushMessageReceiver jPushMessageReceiver = new JPushMessageReceiver() {
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
super.onAliasOperatorResult(context, jPushMessage);
if (jPushMessage.getErrorCode() == 6002) {//超时处理
Message obtain = Message.obtain();
obtain.what = 100;
mHandler.sendMessageDelayed(obtain, 1000 * 60);//60秒后重新验证
}else {
Log.e("onAliasOperatorResult: ", jPushMessage.getErrorCode()+"");
}
}
};
private void setAlias() {
String alias = "";//别名
if ( !alias.isEmpty()) {
JPushInterface.setAlias(getApplicationContext(), TAG, alias);//设置别名或标签
}
}