Skip to content

Commit

Permalink
Use the share intent subject besides the text
Browse files Browse the repository at this point in the history
When sharing a text, some applications also set the subject field in the share intent.
For instance, when sharing a video with NewPipe, the title of the video is put in the subject of the intent.
This change makes use of the subject field when providing the shared text.
  • Loading branch information
raphj authored and moezbhatti committed Feb 29, 2020
1 parent 70f078f commit 5939e45
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -55,14 +55,19 @@ class ComposeActivityModule {
@Provides
@Named("text")
fun provideSharedText(activity: ComposeActivity): String {
return activity.intent.extras?.getString(Intent.EXTRA_TEXT)
var subject = activity.intent.getStringExtra(Intent.EXTRA_SUBJECT) ?: "";
if (subject != "") {
subject += "\n"
}

return subject + (activity.intent.extras?.getString(Intent.EXTRA_TEXT)
?: activity.intent.extras?.getString("sms_body")
?: activity.intent?.decodedDataString()
?.substringAfter('?') // Query string
?.split(',')
?.firstOrNull { param -> param.startsWith("body") }
?.substringAfter('=')
?: ""
?: "")
}

@Provides
Expand All @@ -88,4 +93,4 @@ class ComposeActivityModule {
return data
}

}
}

0 comments on commit 5939e45

Please sign in to comment.