mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Block number in android blocking manager
This commit is contained in:
@@ -19,11 +19,10 @@
|
|||||||
package com.moez.QKSMS.blocking
|
package com.moez.QKSMS.blocking
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.BlockedNumberContract
|
import android.provider.BlockedNumberContract
|
||||||
import android.telecom.TelecomManager
|
|
||||||
import android.telephony.PhoneNumberUtils
|
import android.telephony.PhoneNumberUtils
|
||||||
|
import androidx.core.content.contentValuesOf
|
||||||
import com.moez.QKSMS.extensions.anyOf
|
import com.moez.QKSMS.extensions.anyOf
|
||||||
import com.moez.QKSMS.model.BlockedNumber
|
import com.moez.QKSMS.model.BlockedNumber
|
||||||
import io.reactivex.Completable
|
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 {
|
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
|
||||||
when {
|
when {
|
||||||
Build.VERSION.SDK_INT >= 24 -> {
|
Build.VERSION.SDK_INT >= 24 -> addresses.forEach { address ->
|
||||||
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
val cv = contentValuesOf(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER to address)
|
||||||
val intent = telecomManager.createManageBlockedNumbersIntent()
|
context.contentResolver.insert(BlockedNumberContract.BlockedNumbers.CONTENT_URI, cv)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
context.startActivity(intent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> Realm.getDefaultInstance().use { realm ->
|
else -> Realm.getDefaultInstance().use { realm ->
|
||||||
|
|||||||
Reference in New Issue
Block a user