Reciever manifest sample
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
Get data
if(intent?.action == Intent.ACTION_SEND){
if ("text/plain" == intent.type) {
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
println(text)
}
}
Send data
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
type = "text/plain"
}
startActivity(sendIntent)
URL Scheme
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="www.test.com" />
</intent-filter>
val uri: Uri = Uri.parse("myapp://www.test.com")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)