mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-04 06:00:11 +00:00
parent
cdf0cae0cf
commit
d6b39b09c2
@ -32,7 +32,7 @@ import com.xuexiang.xutil.resource.ResUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
@Suppress("PropertyName", "DEPRECATION")
|
||||
@Suppress("DEPRECATION")
|
||||
class PhoneUtils private constructor() {
|
||||
|
||||
companion object {
|
||||
@ -47,10 +47,10 @@ class PhoneUtils private constructor() {
|
||||
println("1.版本超过5.1,调用系统方法")
|
||||
val mSubscriptionManager = XUtil.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
|
||||
ActivityCompat.checkSelfPermission(
|
||||
XUtil.getContext(), permission.READ_PHONE_STATE
|
||||
XUtil.getContext(), permission.READ_PHONE_STATE
|
||||
)
|
||||
val activeSubscriptionInfoList: List<SubscriptionInfo>? = mSubscriptionManager.activeSubscriptionInfoList
|
||||
if (activeSubscriptionInfoList != null && activeSubscriptionInfoList.isNotEmpty()) {
|
||||
if (!activeSubscriptionInfoList.isNullOrEmpty()) {
|
||||
//1.1.1 有使用的卡,就遍历所有卡
|
||||
for (subscriptionInfo in activeSubscriptionInfoList) {
|
||||
val simInfo = SimInfo()
|
||||
@ -69,9 +69,9 @@ class PhoneUtils private constructor() {
|
||||
val uri = Uri.parse("content://telephony/siminfo") //访问raw_contacts表
|
||||
val resolver: ContentResolver = XUtil.getContext().contentResolver
|
||||
val cursor = resolver.query(
|
||||
uri, arrayOf(
|
||||
uri, arrayOf(
|
||||
"_id", "icc_id", "sim_id", "display_name", "carrier_name", "name_source", "color", "number", "display_number_format", "data_roaming", "mcc", "mnc"
|
||||
), null, null, null
|
||||
), null, null, null
|
||||
)
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
@ -97,7 +97,7 @@ class PhoneUtils private constructor() {
|
||||
//为空,两个卡都没有获取到信息
|
||||
if (infoList.isEmpty()) {
|
||||
//卡1备注信息不为空
|
||||
var etExtraSim1 = SettingUtils.extraSim1
|
||||
val etExtraSim1 = SettingUtils.extraSim1
|
||||
if (!TextUtils.isEmpty(etExtraSim1)) {
|
||||
val simInfo1 = SimInfo()
|
||||
//卡1
|
||||
@ -108,7 +108,7 @@ class PhoneUtils private constructor() {
|
||||
infoList[simInfo1.mSimSlotIndex] = simInfo1
|
||||
}
|
||||
//卡2备注信息不为空
|
||||
var etExtraSim2 = SettingUtils.extraSim2
|
||||
val etExtraSim2 = SettingUtils.extraSim2
|
||||
if (!TextUtils.isEmpty(etExtraSim2)) {
|
||||
val simInfo2 = SimInfo()
|
||||
simInfo2.mSimSlotIndex = 1
|
||||
@ -120,7 +120,7 @@ class PhoneUtils private constructor() {
|
||||
|
||||
//有一张卡,判断是卡几
|
||||
} else {
|
||||
var infoListIndex = -1;
|
||||
var infoListIndex = -1
|
||||
for (obj in infoList) {
|
||||
infoListIndex = obj.key
|
||||
}
|
||||
@ -177,7 +177,7 @@ class PhoneUtils private constructor() {
|
||||
val sendPI = PendingIntent.getBroadcast(XUtil.getContext(), 0, Intent(), sendFlags)
|
||||
|
||||
val smsManager = if (subId > -1 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) SmsManager.getSmsManagerForSubscriptionId(
|
||||
subId
|
||||
subId
|
||||
) else SmsManager.getDefault()
|
||||
// Android 5.1.1 以下使用反射指定卡槽
|
||||
if (subId > -1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
@ -192,7 +192,7 @@ class PhoneUtils private constructor() {
|
||||
if (message.length >= 70) {
|
||||
val deliverFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) PendingIntent.FLAG_IMMUTABLE else 0
|
||||
val deliverPI = PendingIntent.getBroadcast(
|
||||
XUtil.getContext(), 0, Intent("DELIVERED_SMS_ACTION"), deliverFlags
|
||||
XUtil.getContext(), 0, Intent("DELIVERED_SMS_ACTION"), deliverFlags
|
||||
)
|
||||
|
||||
val sentPendingIntents = ArrayList<PendingIntent>()
|
||||
@ -204,7 +204,7 @@ class PhoneUtils private constructor() {
|
||||
deliveredPendingIntents.add(i, deliverPI)
|
||||
}
|
||||
smsManager.sendMultipartTextMessage(
|
||||
mobile, null, divideContents, sentPendingIntents, deliveredPendingIntents
|
||||
mobile, null, divideContents, sentPendingIntents, deliveredPendingIntents
|
||||
)
|
||||
} else {
|
||||
smsManager.sendTextMessage(mobile, null, message, sendPI, null)
|
||||
@ -220,7 +220,7 @@ class PhoneUtils private constructor() {
|
||||
|
||||
//获取通话记录列表
|
||||
fun getCallInfoList(
|
||||
type: Int, limit: Int, offset: Int, phoneNumber: String?
|
||||
type: Int, limit: Int, offset: Int, phoneNumber: String?
|
||||
): MutableList<CallInfo> {
|
||||
val callInfoList: MutableList<CallInfo> = mutableListOf()
|
||||
try {
|
||||
@ -239,7 +239,7 @@ class PhoneUtils private constructor() {
|
||||
|
||||
//为了兼容性这里全部取出后手动分页
|
||||
val cursor = Core.app.contentResolver.query(
|
||||
CallLog.Calls.CONTENT_URI, null, selection, selectionArgs.toTypedArray(), CallLog.Calls.DEFAULT_SORT_ORDER // + " limit $limit offset $offset"
|
||||
CallLog.Calls.CONTENT_URI, null, selection, selectionArgs.toTypedArray(), CallLog.Calls.DEFAULT_SORT_ORDER // + " limit $limit offset $offset"
|
||||
) ?: return callInfoList
|
||||
Log.i(TAG, "cursor count:" + cursor.count)
|
||||
|
||||
@ -280,14 +280,14 @@ class PhoneUtils private constructor() {
|
||||
do {
|
||||
if (curOffset >= offset) {
|
||||
val callInfo = CallInfo(
|
||||
cursor.getString(indexName) ?: "", //姓名
|
||||
cursor.getString(indexNumber) ?: "", //号码
|
||||
cursor.getLong(indexDate), //获取通话日期
|
||||
cursor.getInt(indexDuration), //获取通话时长,值为多少秒
|
||||
cursor.getInt(indexType), //获取通话类型:1.呼入 2.呼出 3.未接
|
||||
if (indexViaNumber != -1) cursor.getString(indexViaNumber) else "", //来源号码
|
||||
if (indexSimId != -1) getSimId(cursor.getInt(indexSimId), isSimId) else -1, //卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||
if (indexSubId != -1) cursor.getInt(indexSubId) else 0, //卡槽主键
|
||||
cursor.getString(indexName) ?: "", //姓名
|
||||
cursor.getString(indexNumber) ?: "", //号码
|
||||
cursor.getLong(indexDate), //获取通话日期
|
||||
cursor.getInt(indexDuration), //获取通话时长,值为多少秒
|
||||
cursor.getInt(indexType), //获取通话类型:1.呼入 2.呼出 3.未接
|
||||
if (indexViaNumber != -1) cursor.getString(indexViaNumber) else "", //来源号码
|
||||
if (indexSimId != -1) getSimId(cursor.getInt(indexSimId), isSimId) else -1, //卡槽ID: 0=Sim1, 1=Sim2, -1=获取失败
|
||||
if (indexSubId != -1) cursor.getInt(indexSubId) else 0, //卡槽主键
|
||||
)
|
||||
Log.d(TAG, callInfo.toString())
|
||||
callInfoList.add(callInfo)
|
||||
@ -318,7 +318,7 @@ class PhoneUtils private constructor() {
|
||||
|
||||
//获取联系人列表
|
||||
fun getContactInfoList(
|
||||
limit: Int, offset: Int, phoneNumber: String?, name: String?
|
||||
limit: Int, offset: Int, phoneNumber: String?, name: String?
|
||||
): MutableList<ContactInfo> {
|
||||
val contactInfoList: MutableList<ContactInfo> = mutableListOf()
|
||||
|
||||
@ -337,7 +337,7 @@ class PhoneUtils private constructor() {
|
||||
Log.d(TAG, "selectionArgs = $selectionArgs")
|
||||
|
||||
val cursor = Core.app.contentResolver.query(
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, selection, selectionArgs.toTypedArray(), ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, selection, selectionArgs.toTypedArray(), ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY
|
||||
) ?: return contactInfoList
|
||||
Log.i(TAG, "cursor count:" + cursor.count)
|
||||
|
||||
@ -352,8 +352,8 @@ class PhoneUtils private constructor() {
|
||||
val mobileNoIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)
|
||||
do {
|
||||
val contactInfo = ContactInfo(
|
||||
cursor.getString(displayNameIndex), //姓名
|
||||
cursor.getString(mobileNoIndex), //号码
|
||||
cursor.getString(displayNameIndex), //姓名
|
||||
cursor.getString(mobileNoIndex), //号码
|
||||
)
|
||||
Log.d(TAG, contactInfo.toString())
|
||||
contactInfoList.add(contactInfo)
|
||||
@ -384,9 +384,9 @@ class PhoneUtils private constructor() {
|
||||
sb.append(ResUtils.getString(R.string.linkman)).append(callInfo.name).append("\n")
|
||||
if (!TextUtils.isEmpty(callInfo.viaNumber)) sb.append(ResUtils.getString(R.string.via_number)).append(callInfo.viaNumber).append("\n")
|
||||
if (callInfo.dateLong > 0L) sb.append(ResUtils.getString(R.string.call_date)).append(
|
||||
DateUtils.millis2String(
|
||||
callInfo.dateLong, SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
)
|
||||
DateUtils.millis2String(
|
||||
callInfo.dateLong, SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
)
|
||||
).append("\n")
|
||||
if (callInfo.duration > 0) {
|
||||
if (callInfo.type == 3) {
|
||||
@ -412,7 +412,7 @@ class PhoneUtils private constructor() {
|
||||
|
||||
// 获取用户短信列表
|
||||
fun getSmsInfoList(
|
||||
type: Int, limit: Int, offset: Int, keyword: String
|
||||
type: Int, limit: Int, offset: Int, keyword: String
|
||||
): MutableList<SmsInfo> {
|
||||
val smsInfoList: MutableList<SmsInfo> = mutableListOf()
|
||||
try {
|
||||
@ -431,7 +431,7 @@ class PhoneUtils private constructor() {
|
||||
|
||||
// 避免超过总数后循环取出
|
||||
val cursorTotal = Core.app.contentResolver.query(
|
||||
Uri.parse("content://sms/"), null, selection, selectionArgs.toTypedArray(), "date desc"
|
||||
Uri.parse("content://sms/"), null, selection, selectionArgs.toTypedArray(), "date desc"
|
||||
) ?: return smsInfoList
|
||||
if (offset >= cursorTotal.count) {
|
||||
cursorTotal.close()
|
||||
@ -439,7 +439,7 @@ class PhoneUtils private constructor() {
|
||||
}
|
||||
|
||||
val cursor = Core.app.contentResolver.query(
|
||||
Uri.parse("content://sms/"), null, selection, selectionArgs.toTypedArray(), "date desc limit $limit offset $offset"
|
||||
Uri.parse("content://sms/"), null, selection, selectionArgs.toTypedArray(), "date desc limit $limit offset $offset"
|
||||
) ?: return smsInfoList
|
||||
|
||||
Log.i(TAG, "cursor count:" + cursor.count)
|
||||
|
Loading…
Reference in New Issue
Block a user