Skip to content

Commit 1cbefab

Browse files
Merge pull request #296 from Idadelveloper/fix-app-trigger
update: extract data from intents from other apps
2 parents d19bb9e + e0af65c commit 1cbefab

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

.kotlin/sessions/kotlin-compiler-3879970839816346169.salive

Whitespace-only changes.

app/src/main/java/com/afkanerd/deku/DefaultSMS/MainActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.afkanerd.deku.DefaultSMS
22

33
import android.Manifest
4+
import android.annotation.SuppressLint
45
import android.app.Activity
6+
import android.app.ComponentCaller
57
import android.content.Intent
68
import android.content.pm.PackageManager
79
import android.net.Uri
810
import android.os.Bundle
911
import android.os.ParcelFileDescriptor
1012
import android.provider.Telephony
1113
import android.text.Layout
14+
import android.util.Log
1215
import android.widget.Toast
1316
import androidx.activity.compose.setContent
1417
import androidx.activity.enableEdgeToEdge
@@ -64,6 +67,7 @@ import java.io.InputStreamReader
6467
import androidx.compose.runtime.getValue
6568
import androidx.compose.runtime.setValue
6669
import androidx.compose.ui.Alignment
70+
import androidx.compose.ui.input.key.type
6771
import androidx.compose.ui.res.stringResource
6872
import androidx.compose.ui.text.font.FontStyle
6973
import androidx.compose.ui.text.style.LineHeightStyle
@@ -107,6 +111,12 @@ class MainActivity : AppCompatActivity(){
107111
}
108112
}
109113

114+
override fun onNewIntent(intent: Intent, caller: ComponentCaller) {
115+
super.onNewIntent(intent, caller)
116+
this.intent = intent
117+
navController.navigate(HomeScreen)
118+
}
119+
110120
private fun checkLoadNatives() {
111121
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
112122
if(sharedPreferences.getBoolean(getString(R.string.configs_load_natives), false)){

app/src/main/java/com/afkanerd/deku/DefaultSMS/ui/ThreadsConversationMain.kt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.provider.BlockedNumberContract
77
import android.provider.ContactsContract
88
import android.provider.Telephony
99
import android.text.InputType
10+
import android.util.Log
1011
import android.widget.Toast
1112
import androidx.activity.compose.BackHandler
1213
import androidx.activity.result.contract.ActivityResultContracts
@@ -213,21 +214,34 @@ fun processIntents(
213214
): Triple<String?, String?, String?>?{
214215
if(intent.action != null &&
215216
((intent.action == Intent.ACTION_SENDTO) || (intent.action == Intent.ACTION_SEND))) {
217+
val text = if(intent.hasExtra("sms_body")) intent.getStringExtra("sms_body")
218+
else if(intent.hasExtra("android.intent.extra.TEXT")) {
219+
intent.getStringExtra("android.intent.extra.TEXT")
220+
} else ""
221+
216222
val sendToString = intent.dataString
217-
val text = if(intent.hasExtra("sms_body")) intent.getStringExtra("sms_body") else ""
218-
if (sendToString != null &&
219-
(sendToString.contains("smsto:") || sendToString.contains("sms:"))
223+
224+
if ((
225+
sendToString != null &&
226+
(sendToString.contains("smsto:") ||
227+
sendToString.contains("sms:"))) ||
228+
intent.hasExtra("address")
220229
) {
221-
val address = Helpers.getFormatCompleteNumber(sendToString, defaultRegion)
230+
231+
val address = Helpers.getFormatCompleteNumber(
232+
if(intent.hasExtra("address")) intent.getStringExtra("address")
233+
else sendToString, defaultRegion)
234+
222235
val threadId =
223236
ThreadedConversationsHandler.get(context, address)
224237
.thread_id
225-
226238
return Triple(address, threadId, text)
227239
}
228240
}
229241
else if(intent.hasExtra("address")) {
230-
var text = ""
242+
var text = if(intent.hasExtra("android.intent.extra.TEXT"))
243+
intent.getStringExtra("android.intent.extra.TEXT") else ""
244+
231245
val address = intent.getStringExtra("address")
232246
val threadId = intent.getStringExtra("thread_id")
233247
return Triple(address, threadId, text)
@@ -510,12 +524,14 @@ fun ThreadConversationLayout(
510524
val context = LocalContext.current
511525

512526
intent?.let {
527+
// conversationsViewModel.text = ""
513528
val defaultRegion = if(inPreviewMode) "cm" else Helpers.getUserCountry(context)
514529
processIntents(context, intent, defaultRegion)?.let {
515530
intent.apply {
516531
removeExtra("address")
517532
removeExtra("thread_id")
518533
removeExtra("sms_body")
534+
removeExtra("android.intent.extra.TEXT")
519535
data = null
520536
}
521537
it.first?.let{ address ->
@@ -534,7 +550,6 @@ fun ThreadConversationLayout(
534550
}
535551
}
536552
}
537-
conversationsViewModel.text = ""
538553

539554
val counts by conversationsViewModel.getCount(context).observeAsState(null)
540555

0 commit comments

Comments
 (0)