A simple way to send a link to another app!
A few days ago I needed to be able to send a link to an external app, and Intents are perfect for such task, Android through the Sharesheet allows you to do so (unless you want to implement a custom one).
Just need to call Intent.createChooser(intent, null) and start the activity; now, if you want to be able to detect which app the user chooses to share the link with, we would need to include the broadcaster (only available from API 22) and once the onReceived is called, obtain the ClickedComponent by getting the extra from the intent with Intent.EXTRA_CHOSEN_COMPONENT, this will give you access to the package name of the app selected.
The main call would look something like this (Don’t forget the MIME type, in my case is “text/plain”):
On your BroadcastReceiver onReceived method:
What about if I want to listen when the user decides to just copy the link? In that case, we could do so by listening changes on the clipboard:
The logcat output would be:
You can find a mini example here GitHub
Pigeon image credit: iStockphoto/IEEE Spectrum
Comments