Android Code Snippet Share image using Facebook App

Discussion in 'Code Snippets' started by asales, Jun 8, 2015.

  1. asales

    asales Well-Known Member Licensed User

    I'm using this code to post an image in Facebook with the Facebook app of the device.

    I don't need create a Facebook App to get "App ID" and "App Secret" to share (until now).

    The step 2 ("select the intent...") is because I found differents intents of Facebook app to share an image in several versions of Android (2.3.6, 4.0, 4.4, 5.0):
    - com.facebook.katana/com.facebook.composer.shareintent.ImplicitShareIntentHandler
    - com.facebook.katana/com.facebook.composer.shareintent.ImplicitShareIntentHandlerDefaultAlias
    - com.facebook.katana/.ComposerActivity

    I'll be glad to anyone who can test this code (example B4A 4.30 in attached) and any tip to help improve it.

    Libraries: Phone (uri) and ContentResolver (packagemanager).

    Sub PostImageFacebook
    '1. copy the image to File.DirDefaultExternal
        File.Copy(File.DirAssets, "android.jpg"File.DirDefaultExternal, "android.jpg")
    '2. select the image
        Dim u As Uri
    "file://" & File.Combine(File.DirDefaultExternal,"android.jpg"))

    Dim pm As PackageManager
    Dim fb1 As String
    '3. select the intent of facebook to share image
        Dim i As Intent
    For Each cn As String In pm.QueryIntentActivities(i)
    If cn.SubString2(0,20) = "com.facebook.katana/" Then
                  fb1 = cn
    End If


    '4. start intent
    End Try 
    End Sub

    Attached Files:

    koaunglay, MarcoRome and hibrid0 like this.
  2. Douglas Farias

    Douglas Farias Expert Licensed User

    thx as2, know about text?
  3. asales

    asales Well-Known Member Licensed User

    I don't know how to post a text, yet.
    Douglas Farias likes this.
  4. Petrovic

    Petrovic Member Licensed User

    Is this still working after facebook changed permissions?
  5. asales

    asales Well-Known Member Licensed User

    Yes. Check the example.
  6. asales

    asales Well-Known Member Licensed User

  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