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

Discussion in 'Code Snippets' started by hatzisn, Nov 25, 2018.

  1. hatzisn

    hatzisn Active Member Licensed User

    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...

    Code:
    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: Nov 25, 2018
    Alexander Stolte, yiankos1 and Almora like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice