add data SMS receiving

This commit is contained in:
Joel Beckmeyer 2024-04-22 10:10:37 -04:00
parent a932d440eb
commit 76bd47869d
3 changed files with 13 additions and 1 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -32,6 +32,8 @@
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/> <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.intent.action.DATA_SMS_RECEIVED"/>
<data android:host="localhost" android:port="5499" android:scheme="sms"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
</application> </application>

View File

@ -15,7 +15,8 @@ class SmsReceiver : BroadcastReceiver() {
@OptIn(ExperimentalStdlibApi::class) @OptIn(ExperimentalStdlibApi::class)
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Telephony.Sms.Intents.SMS_RECEIVED_ACTION) { if (intent.action == Telephony.Sms.Intents.SMS_RECEIVED_ACTION ||
intent.action == Telephony.Sms.Intents.DATA_SMS_RECEIVED_ACTION) {
val bundle: Bundle? = intent.extras val bundle: Bundle? = intent.extras
bundle?.let { bundle?.let {
val pdus = bundle.get("pdus") as Array<ByteArray> val pdus = bundle.get("pdus") as Array<ByteArray>
@ -23,6 +24,9 @@ class SmsReceiver : BroadcastReceiver() {
val smsMessage = val smsMessage =
SmsMessage.createFromPdu(pdu, bundle.getString("format")) SmsMessage.createFromPdu(pdu, bundle.getString("format"))
smsMessage?.let { smsMessage?.let {
if (intent.action == Telephony.Sms.Intents.DATA_SMS_RECEIVED_ACTION) {
Log.d(TAG, "Data SMS received on port 5499")
}
val messageBody = smsMessage.messageBody val messageBody = smsMessage.messageBody
Log.d(TAG, "Message body: $messageBody") Log.d(TAG, "Message body: $messageBody")
val pduHexString = pdu.toHexString() val pduHexString = pdu.toHexString()