Skip to content

Commit

Permalink
Add intent to receive selected text through share menu. (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirkarthi authored Feb 10, 2024
1 parent 70adf38 commit 1d08591
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ open class ProcessIntentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val word: String
val context = applicationContext
val word = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT).toString().lowercase()
if (intent?.action == Intent.ACTION_SEND && intent.type == "text/plain") {
word = intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString().lowercase()
} else {
word = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT).toString().lowercase()
}

val executor = Executors.newSingleThreadExecutor()
var definition = "No meaning found"
Expand Down Expand Up @@ -272,4 +277,4 @@ open class ProcessIntentActivity : AppCompatActivity() {

class ProcessViewActivity : ProcessIntentActivity()

class ProcessTextActivity : ProcessIntentActivity()
class ProcessTextActivity : ProcessIntentActivity()

0 comments on commit 1d08591

Please sign in to comment.