| | |
| | | import android.os.* |
| | | import android.util.Log |
| | | import androidx.annotation.RequiresApi |
| | | import cn.jpush.android.api.JPushInterface |
| | | import cn.jpush.android.api.TagAliasCallback |
| | | import cn.sinata.rxnetty.NettyClient |
| | | import cn.sinata.xldutils.BaseApplication |
| | | import cn.sinata.xldutils.utils.sysErr |
| | |
| | | import com.fuban.driver.utils.Cache.CacheUtil |
| | | import com.fuban.driver.utils.LogUtils |
| | | import com.google.gson.Gson |
| | | import com.tencent.bugly.crashreport.CrashReport |
| | | import com.umeng.commonsdk.UMConfigure |
| | | import com.umeng.socialize.PlatformConfig |
| | | import com.xuexiang.xui.XUI |
| | |
| | | ) |
| | | PlatformConfig.setWeixin("wx19a713b4943f9568", "5d4ca951a855b1e2c86a844cd42fd133") |
| | | PlatformConfig.setQQZone("1112151767", "5viZ7mQkNkYtUr7b") //qq互联 |
| | | JPushInterface.setDebugMode(true) |
| | | JPushInterface.init(this) |
| | | setAlisa() |
| | | } |
| | | |
| | | public fun setAlisa() { |
| | | if (CacheKey.getUserId().isNotEmpty()) { |
| | | var alisa = "DRIVER" + CacheKey.getUserId() |
| | | sysErr(alisa) |
| | | mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_ALIAS, alisa)) |
| | | } |
| | | } |
| | | |
| | | private val MSG_SET_ALIAS = 1001 |
| | | private val mHandler: Handler = object : Handler() { |
| | | override fun handleMessage(msg: Message) { |
| | | super.handleMessage(msg) |
| | | when (msg.what) { |
| | | MSG_SET_ALIAS -> { |
| | | Log.d(TAG, "Set alias in handler.") |
| | | // 调用 JPush 接口来设置别名。 |
| | | JPushInterface.setAliasAndTags( |
| | | applicationContext, |
| | | msg.obj as String, |
| | | null, |
| | | mAliasCallback |
| | | ) |
| | | } |
| | | else -> Log.i(TAG, "Unhandled msg - " + msg.what) |
| | | } |
| | | } |
| | | } |
| | | |
| | | private val mAliasCallback = |
| | | TagAliasCallback { code, alias, tags -> |
| | | val logs: String |
| | | when (code) { |
| | | 0 -> { |
| | | logs = "Set tag and alias success" |
| | | Log.i("TAG", logs) |
| | | } |
| | | 6002 -> { |
| | | logs = "Failed to set alias and tags due to timeout. Try again after 60s." |
| | | Log.i("TAG", logs) |
| | | // 延迟 60 秒来调用 Handler 设置别名 |
| | | var alisa = "DRIVER" + CacheKey.getUserId() |
| | | Handler().postDelayed({ |
| | | JPushInterface.setAliasAndTags(this, alisa, null, null) |
| | | }, 60 * 1000) |
| | | } |
| | | else -> { |
| | | logs = "Failed with errorCode = $code" |
| | | Log.e("TAG", logs) |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private fun initSocket() { |
| | | NettyClient.getInstance().init(this, Api.SOCKET_SERVER, Api.SOCKET_PORT, true) |