Android Code Snippet Instagram and Twitter share image and text with intent

tpakis

Active Member
Licensed User
A little code to share an image to instagram using an intent. Hope it's usefull :)

B4X:
Dim u As Uri 'ContentResolver library
u.Parse("file://" & File.Combine(a, "tmpfile.jpg"))
Dim inten As Intent
Dim tmpt As String = "your text"
inten.Initialize(inten.ACTION_SEND,"")
inten.SetType("image/*")
inten.PutExtra("android.intent.extra.STREAM",u)
inten.PutExtra("android.intent.extra.TEXT",tmpt)
inten.SetComponent("com.instagram.android/.activity.ShareHandlerActivity")
StartActivity(inten)
if you want to Twitter just change:
B4X:
inten.SetComponent("com.twitter.android/.composer.ComposerActivity")
 
Last edited:

Beja

Expert
Licensed User
Hi tpakis,
Is there anyway to know how money people visited my account (just visit without like or dislike)?
Thanks in advance
 

tpakis

Active Member
Licensed User
for instagram the code changed to inten.SetComponent("com.instagram.android/.activity.ShareHandlerActivity")
 

sasetcolombia

Member
Licensed User
Hi tpakis,
I implemented the code with the respective image and path, but when calling the intent, is shows the main activity of Instagram, with the options
inico, search, gallery, activity.... but the image does not appear set.The gallery is the android gallery.
How could open the intent, to set the directory where the image to share?
Thanks!
 

karyadi

Member
Licensed User
hi, i try using intent to post image and text to twitter and instagram, but text now show up? what wrong?
 

asales

Well-Known Member
Licensed User
New components strings that will handled this intents:
B4X:
Twitter:
com.twitter.android/com.twitter.composer.SelfThreadComposerActivity

Instagram:
com.instagram.android/com.instagram.share.common.ShareHandlerActivity
 

asales

Well-Known Member
Licensed User
(Again) New components strings that will handled this intents:
Twitter:
B4X:
com.twitter.android/com.twitter.composer.ComposerActivity
Instagram:
B4X:
com.instagram.android/com.instagram.share.handleractivity.ShareHandlerActivity
Now I use this code to check the new strings (even if Instagram and Twitter change it):

B4X:
Dim IntentInstagram As String
Dim IntentTwitter As String
Dim pm As PackageManager
    
For Each cn As String In pm.QueryIntentActivities(inten)
       'Instagram
       If cn.SubString2(0,19) = "com.twitter.android" Then
           IntentTwitter = cn
           Exit
       End If

      'OR

       'Twitter
       If cn.SubString2(0,21) = "com.instagram.android" Then
            IntentInstagram = cn
            Exit
       End If
Next
 
Top