Block number in android blocking manager

This commit is contained in:
moezbhatti
2019-06-23 19:02:42 -04:00
parent a3824825f6
commit f2e736b638
@@ -19,11 +19,10 @@
package com.moez.QKSMS.blocking
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.BlockedNumberContract
import android.telecom.TelecomManager
import android.telephony.PhoneNumberUtils
import androidx.core.content.contentValuesOf
import com.moez.QKSMS.extensions.anyOf
import com.moez.QKSMS.model.BlockedNumber
import io.reactivex.Completable
@@ -44,15 +43,13 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block
}
}
override fun canBlock(): Boolean = Build.VERSION.SDK_INT < 24
override fun canBlock(): Boolean = true
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
when {
Build.VERSION.SDK_INT >= 24 -> {
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
val intent = telecomManager.createManageBlockedNumbersIntent()
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
Build.VERSION.SDK_INT >= 24 -> addresses.forEach { address ->
val cv = contentValuesOf(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER to address)
context.contentResolver.insert(BlockedNumberContract.BlockedNumbers.CONTENT_URI, cv)
}
else -> Realm.getDefaultInstance().use { realm ->