How can I share something with other Android apps?
Example, in my screen I have a text field. I would like to be able to share the text content with WhatsApp by clicking on the button. Where should I start from?
Thanks
Gabriel
You could create an Android Library (you can read more about at Creating an Android Library with Kotlin for use with Xojo) and use the following Kotlin code:
fun sendMessage(con: Any?, message: String?) {
val newCon: Context
if (con is Context)
newCon = con
else
throw NullPointerException()
// Creating intent with action send
val intent = Intent(Intent.ACTION_SEND)
// Setting Intent type
intent.type = "text/plain"
// Setting whatsapp package name
intent.setPackage("com.whatsapp")
// Give your message here
intent.putExtra(Intent.EXTRA_TEXT, message)
try {
intent.setFlags(FLAG_ACTIVITY_NEW_TASK)
// startActivity wants a context parameter before the indent parameter
startActivity(newCon, intent, null)
} catch (e: ActivityNotFoundException) {
// Define what your app should do if no activity can handle the intent.
}
}
And the Xojo Declare should look kind like this:
Declare Sub sendMessage Lib "com.example.utility.regex" (context As Ptr, message As CString)
sendMessage(App.AndroidContextHandle, "Hello World")
Give it a try, not tested, but should be the way to go.
1 Like
Thanks!
I was doing some testing and found this solution already integrated into the framework:
dim mbSharing as new MobileSharingPanel
mbSharing.ShareText("Test my text sharing")
1 Like