优化:单 sim 卡槽手机不显示 sim2 设置。

This commit is contained in:
kvii 2024-11-06 11:45:12 +08:00 committed by pppscn
parent 3adfffee4f
commit dc3726d0de
3 changed files with 22 additions and 6 deletions

View File

@ -180,12 +180,18 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
editAddExtraDeviceMark(binding!!.etExtraDeviceMark)
//SIM1主键
editAddSubidSim1(binding!!.etSubidSim1)
//SIM2主键
editAddSubidSim2(binding!!.etSubidSim2)
//SIM1备注
editAddExtraSim1(binding!!.etExtraSim1)
//SIM2备注
editAddExtraSim2(binding!!.etExtraSim2)
// sim 槽只有一个的时候不显示 SIM2 设置
if (PhoneUtils.getSimSlotCount() != 1) {
//SIM2主键
editAddSubidSim2(binding!!.etSubidSim2)
//SIM2备注
editAddExtraSim2(binding!!.etExtraSim2)
} else {
binding!!.layoutSim2.visibility = View.GONE
}
//通知内容
editNotifyContent(binding!!.etNotifyContent)
//启用自定义模版
@ -991,7 +997,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
//设置SIM1主键
private fun editAddSubidSim1(etSubidSim1: EditText) {
etSubidSim1.setText(SettingUtils.subidSim1.toString())
etSubidSim1.setText("${SettingUtils.subidSim1}")
etSubidSim1.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
@ -1008,7 +1014,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
//设置SIM2主键
private fun editAddSubidSim2(etSubidSim2: EditText) {
etSubidSim2.setText(SettingUtils.subidSim2.toString())
etSubidSim2.setText("${SettingUtils.subidSim2}")
etSubidSim2.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}

View File

@ -14,6 +14,7 @@ import android.provider.Settings
import android.telephony.SmsManager
import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
import android.text.TextUtils
import androidx.annotation.RequiresPermission
import androidx.core.app.ActivityCompat
@ -37,6 +38,14 @@ class PhoneUtils private constructor() {
companion object {
const val TAG = "PhoneUtils"
/** 获取 sim 卡槽数量,注意不是 sim 卡的数量。*/
fun getSimSlotCount() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
(App.context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).activeModemCount
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
(App.context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).phoneCount
else
-1
//获取多卡信息
@SuppressLint("Range")
fun getSimMultiInfo(): MutableMap<Int, SimInfo> {

View File

@ -1567,6 +1567,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/layout_sim2"
style="@style/BarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"