Android Code Snippet Share text messages in all social (and not) apps

Here is a code I developed with cooking and mixing of given recipies... Share text (you can include URIs) in every social app and more... Use it in activities. Have fun...

B4X:
Sub ShareMessage(sMes As String, app As String)
   Dim i As Intent
   Dim jo As JavaObject
   jo.InitializeContext
   Dim sPackage As String
   Select Case app.ToLowerCase
       Case "facebook"
           sPackage = "com.facebook.katana"
       Case "twitter"
           sPackage = "com.twitter.android"
       Case "viber"
           sPackage = "com.viber.voip"
       Case "messenger"
           sPackage = "com.facebook.orca"
       Case "instagram"
           sPackage = "com.instagram.android"
       Case "whatsapp"
           sPackage = "com.whatsapp"
       Case "choose"
           sPackage = "choose"
   End Select
 
   i = jo.RunMethod("intnt", Array As String(sMes, sPackage))
   StartActivity(i)
End Sub


#If JAVA

import android.content.Intent;

public Intent intnt(String message, String applicationpackage){
   Intent i = new Intent(Intent.ACTION_SEND);
   i.setType("text/plain");
   i.putExtra(Intent.EXTRA_TEXT, message);
   if (applicationpackage=="choose"){
       return Intent.createChooser(i,"Share using");
   }else{
       i.setPackage(applicationpackage);
       return i;
   }
};

#End If
 
Last edited:
Top