Share something with other android apps

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

This is useful for creating a text file, such as a tab-delimited or CSV file, as you can send it to Google Drive or OneDrive. You can also send it to Keep Notes.
Unfortunately when you do so, you have to manually name the file, otherwise it has the name, “Subject Here” (also as a Keep Notes title).

My Android App is coming along, but it’s disappointing that I have to find so many workarounds, and still come across frequent dead-ends without an in-IDE solution.

I read about suggestions for creating Java or Kotlin routines that I could Declare in Xojo, but to be honest, if I had wanted to programme in Android Studio then I would haven’t purchased Xojo

2 Likes