我正在开发一个应用程序,拨号一些USSD和等待短信与他们有关。它在双SIM手机中使用两个SIM插槽。我需要确定哪个SIM (例如时隙索引)收到了特定的SMS。我可以得到它当收到短信使用BroadcastReceiver。但如果我错过了一些广播(例如,用户卸载应用程序->短信接收->应用程序重新安装的)。在这个场景中,我必须在我的应用程序进程每次启动后重新检查消息。
我正在用ContentProvider阅读短信
val cursor = resolver.query(Uri.parse("content://sms/inbox"), null, null, null, null)在android中,有一个名为sub_id (即Telephony.TextBasedSmsColumns.SUBSCRIPTION_ID)的列。但我无法从我的测试设备Xiaomi Redmi 5 Plus, MIUI Global 11.0.2, Android 8.1.0获得该列。当我试图使用获取该列时,它会抛出异常,说明只有可用的列为:[_id, thread_id, address, person, date, date_sent, protocol, read, status, type, reply_path_present, subject, body, service_center, locked, error_code, seen, timed, deleted, sync_state, marker, source, bind_id, mx_status, mx_id, mx_id_v2, out_time, account, sim_id, block_type, advanced_seen, b2c_ttl, b2c_numbers, fake_cell_type, url_risky_type, creator, favorite_date]。
编辑:注意到sim_id给了我更大的值,比如11, 13, 14等等。无论如何,我不能将它们映射到sim插槽。
发布于 2022-02-13 17:53:38
我终于得到了它,sim_id相当于文档中的sub_id列。因此,我们在使用android时需要小心。
fun findSlotFromSubId(sm: SubscriptionManager, subId: Int): Int {
try {
for (s in sm.activeSubscriptionInfoList) {
if (s.subscriptionId == subId) {
return s.simSlotIndex
}
}
} catch (e: SecurityException) {
e.printStackTrace()
}
return -1
}https://stackoverflow.com/questions/71103030
复制相似问题