-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMSReceiver.kt
More file actions
58 lines (47 loc) · 2.29 KB
/
SMSReceiver.kt
File metadata and controls
58 lines (47 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.example.testsmpp
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.provider.Telephony
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import java.util.concurrent.TimeUnit
class SMSReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION == intent.action) {
val smsMessages = Telephony.Sms.Intents.getMessagesFromIntent(intent)
for (message in smsMessages) {
val body = message.messageBody
val phoneNumber = message.displayOriginatingAddress
Log.v("SMSReceiver",body)
Log.v("SMSReceiver",phoneNumber.removePrefix("+98"))
//
val sharedPref = context.getSharedPreferences("gateway_config",
AppCompatActivity.MODE_PRIVATE
)
val key = sharedPref.getString("key", "")
try {
val deText = SecurityUtil.decryptText(body, key.toString())
val mainActivityIntent = Intent(context, MainActivity::class.java)
if(!deText.contains("| AFTSTC")) {
//Create a new intent to send the data to MainActivity
mainActivityIntent.putExtra("isReceive", true)
mainActivityIntent.putExtra("phoneNumber", phoneNumber.removePrefix("+98"))
mainActivityIntent.putExtra("text", deText)
}
else
{
mainActivityIntent.putExtra("ackReceive", true)
mainActivityIntent.putExtra("ackPhoneNumber", phoneNumber.removePrefix("+98"))
mainActivityIntent.putExtra("ackText", deText.removeSuffix(" | AFTSTC"))
}
// Start the MainActivity with the new intent
mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
context.startActivity(mainActivityIntent)
} catch (e: Exception) {
Log.v("decrypt","Error occurred during decryption: ${e.message}")
}
}
}
}
}