| | |
| | | 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 |
| | |
| | | handleSSLHandshake() |
| | | //如果是主进程 |
| | | XUI.init(this) |
| | | registerActivityLifecycleCallbacks(this) |
| | | // CrashReport.initCrashReport(getApplicationContext(), "444bb776ed", false); |
| | | LogUtils.OpenLog(true) |
| | | initUpPoint() |
| | | initSocket() |
| | | } |
| | | |
| | | /** |
| | | * 延迟初始化,在用户同意隐私协议后进行 |
| | | */ |
| | | fun initSdk(){ |
| | | UMConfigure.init( |
| | | this, |
| | | "640ae80cba6a5259c41ab641", |
| | |
| | | UMConfigure.DEVICE_TYPE_PHONE, |
| | | "" |
| | | ) |
| | | registerActivityLifecycleCallbacks(this) |
| | | PlatformConfig.setWeixin("wx19a713b4943f9568", "5d4ca951a855b1e2c86a844cd42fd133") |
| | | PlatformConfig.setQQZone("1112151767", "5viZ7mQkNkYtUr7b") //qq互联 |
| | | // CrashReport.initCrashReport(getApplicationContext(), "444bb776ed", false); |
| | | LogUtils.OpenLog(true) |
| | | initUpPoint() |
| | | initSocket() |
| | | 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) |
| | |
| | | |
| | | companion object { |
| | | private const val TAG = "MyApplication" |
| | | var canPlayVoice = false //进入主页才可以播放语言通知 |
| | | protected var mTtsManager: TTSController? = null |
| | | public var isLogin: Boolean = true |
| | | |
| | |
| | | showNum-- |
| | | Handler(Looper.getMainLooper()).postDelayed({ |
| | | if (showNum == 0) { |
| | | getTTsManager().setVideoText("福伴出行司机已置于后台,可能会导致听单异常,里程计费差异,请勿切换。") |
| | | if (canPlayVoice) |
| | | getTTsManager().setVideoText("福伴司机已置于后台,可能会导致听单异常,里程计费差异,请勿切换。") |
| | | } |
| | | }, 600) |
| | | |