1

我正在为我的 Voip 应用程序使用 Csipsimple。当我单击注销按钮时,登录屏幕出现,但是当我在此号码上注销后呼叫时,来电即将到来并且呼叫已连接。

fun disconnect(quit: Boolean, ctx: Context?) {
        try {
            val intent = Intent(SipManager.ACTION_OUTGOING_UNREGISTER)
            intent.putExtra(SipManager.EXTRA_OUTGOING_ACTIVITY, ComponentName(ctx, MainActivity::class.java))
            ctx!!.sendBroadcast(intent)

            val pref = PrefManager(ctx)
            pref.setLoggedIn(false)
            val crMain = ChattingClass()
            crMain.logoutFromChat(this)
            if (quit) {
                // also delete the shared preference when disconnect
                deleteUserFromPref(ctx)
                val finish = Intent(ctx, LoginMainActivity::class.java)
                finish.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
                finish.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                (ctx as Activity).startActivity(finish)
                (ctx as Activity).finish()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

我在单击注销按钮时调用此断开连接方法。我正在注销 sip 连接并清除共享首选项。

4

1 回答 1

0

经过一些研究和更改我的 prefProviderWrapper 类中的一些代码后,我得到了 CsipSimple 帐户注销的完美解决方案。

private var prefProviderWrapper: PreferencesProviderWrapper? = null

   fun disconnect(quit: Boolean, ctx: Context?) {
        try {
            prefProviderWrapper = PreferencesProviderWrapper(ctx)
            prefProviderWrapper!!.setPreferenceBooleanValue(PreferencesWrapper.HAS_BEEN_QUIT, true)
            val intent = Intent(SipManager.ACTION_OUTGOING_UNREGISTER)
            intent.putExtra(SipManager.EXTRA_OUTGOING_ACTIVITY, ComponentName(ctx, MainActivity::class.java))
            ctx!!.sendBroadcast(intent)

            val pref = PrefManager(ctx)
            pref.setLoggedIn(false)
            val crMain = ChattingClass()
            crMain.logoutFromChat(this)
            if (quit) {
                // also delete the shared preference when disconnect
                deleteUserFromPref(ctx)
                val finish = Intent(ctx, LoginMainActivity::class.java)
                finish.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
                finish.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                (ctx as Activity).startActivity(finish)
                (ctx as Activity).finish()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
于 2019-05-22T07:04:35.567 回答