单击注销按钮时如何从Csipsimple帐户注销?

时间:2019-03-18 11:52:08

标签: android voip voip-android

我正在为我的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连接并清除共享首选项。

1 个答案:

答案 0 :(得分: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()
        }