mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-09 19:10:51 +00:00
新增:短信指令增加短信发送功能 #338
This commit is contained in:
parent
703ca25e7c
commit
103b1f5839
@ -493,6 +493,8 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
|||||||
.permission(Permission.WRITE_SETTINGS)
|
.permission(Permission.WRITE_SETTINGS)
|
||||||
// 接收短信
|
// 接收短信
|
||||||
.permission(Permission.RECEIVE_SMS)
|
.permission(Permission.RECEIVE_SMS)
|
||||||
|
// 发送短信
|
||||||
|
.permission(Permission.SEND_SMS)
|
||||||
// 读取短信
|
// 读取短信
|
||||||
.permission(Permission.READ_SMS).request(object : OnPermissionCallback {
|
.permission(Permission.READ_SMS).request(object : OnPermissionCallback {
|
||||||
override fun onGranted(permissions: List<String>, all: Boolean) {
|
override fun onGranted(permissions: List<String>, all: Boolean) {
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
package com.idormy.sms.forwarder.utils
|
package com.idormy.sms.forwarder.utils
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import com.google.gson.Gson
|
||||||
import com.idormy.sms.forwarder.App
|
import com.idormy.sms.forwarder.App
|
||||||
|
import com.idormy.sms.forwarder.R
|
||||||
import com.idormy.sms.forwarder.database.AppDatabase
|
import com.idormy.sms.forwarder.database.AppDatabase
|
||||||
|
import com.idormy.sms.forwarder.server.model.SmsSendData
|
||||||
import com.idormy.sms.forwarder.service.HttpService
|
import com.idormy.sms.forwarder.service.HttpService
|
||||||
import com.xuexiang.xrouter.utils.TextUtils
|
import com.xuexiang.xrouter.utils.TextUtils
|
||||||
|
import com.xuexiang.xui.utils.ResUtils
|
||||||
|
import com.xuexiang.xutil.XUtil
|
||||||
import com.xuexiang.xutil.file.FileUtils
|
import com.xuexiang.xutil.file.FileUtils
|
||||||
import com.xuexiang.xutil.system.DeviceUtils
|
import com.xuexiang.xutil.system.DeviceUtils
|
||||||
import frpclib.Frpclib
|
import frpclib.Frpclib
|
||||||
@ -121,6 +129,36 @@ class SmsCommandUtils {
|
|||||||
wifiManager.isWifiEnabled = false
|
wifiManager.isWifiEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"sms" -> {
|
||||||
|
if (action == "send") {
|
||||||
|
if (TextUtils.isEmpty(param)) return false
|
||||||
|
|
||||||
|
try {
|
||||||
|
val gson = Gson()
|
||||||
|
val smsSendData = gson.fromJson(param, SmsSendData::class.java)
|
||||||
|
Log.d(TAG, smsSendData.toString())
|
||||||
|
|
||||||
|
//获取卡槽信息
|
||||||
|
if (App.SimInfoList.isEmpty()) {
|
||||||
|
App.SimInfoList = PhoneUtils.getSimMultiInfo()
|
||||||
|
}
|
||||||
|
Log.d(TAG, App.SimInfoList.toString())
|
||||||
|
|
||||||
|
//发送卡槽: 1=SIM1, 2=SIM2
|
||||||
|
val simSlotIndex = smsSendData.simSlot - 1
|
||||||
|
//TODO:取不到卡槽信息时,采用默认卡槽发送
|
||||||
|
val mSubscriptionId: Int = App.SimInfoList[simSlotIndex]?.mSubscriptionId ?: -1
|
||||||
|
|
||||||
|
if (ActivityCompat.checkSelfPermission(XUtil.getContext(), Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
PhoneUtils.sendSms(mSubscriptionId, smsSendData.phoneNumbers, smsSendData.msgContent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Parsing SMS failed: " + e.message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user