B4A Library Social Share Library

(2020-06-09) SocialShare library is now b4xlib (B4A & B4i). The old code for B4A is shown further bellow (it has changed a bit) and for B4XPages is the following:

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private sc As SocialShare
  
End Sub

Public Sub Initialize
  
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    sc.Initialize(B4XPages.GetNativeParent(Me), Root)
  
End Sub


Sub Button1_Click

    'For b4i only ChooseChannel is exposed just to make it clearer but if you put also empty string it will work
    sc.ShareMessage("Trial message with url: https://www.google.com", sc.ChooseChannel)
 
#If B4A
    'For B4A you select social channel
    'For example
    sc.ShareMessage("This is a trial message with a URL for Viber  https://www.google.com", sc.Viber)
    'OR
    sc.ShareMessage("This is a trial message with a URL for Twitter   https://www.google.com", sc.Twitter)
#End if
End sub



(2019-02-16) The Enum SocialChannel was removed (because it was practically useless) and the library use has changed. Please see the code bellow on the new usage.



Hi everyone,

This is a library to share text in all social apps and not only... I compiled the code into a library and made it a lot easier for me and for everyone to use it. Usage:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Social As SocialShare
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Share")

    'Added args in the initialization
    Social.Initialize(Me, Activity)

End Sub



Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub cmdViber_Click
    Social.ShareMessage("This is a trial message with a URL for Viber  https://www.google.com", Social.Viber)
End Sub

Sub cmdTwitter_Click
    Social.ShareMessage("This is a trial message with a URL for Twitter   https://www.google.com", Social.Twitter)
End Sub

Thanks to the excelent Martin Pearman's tool the description is as follows:


NHSocialShare
Author:
Nikolaos Hatzistelios
Version: 1.1

  • Fields:
    • Facebook As String
    • Twitter As String
    • Viber As String
    • FacebookMessenger As String
    • Instagram As String
    • Whatsapp As String
    • Skype As String
    • Choosechannel As String

  • Methods
    • IsInitialized As boolean
      Tests whether the object has been initialized.
    • Initialize (ba As anywheresoftware.b4a.BA) As String
      Initializes the object. You can add parameters to this method if needed.
    • Sharemessage (Message As String, SocialChannelClassValue As String) As String

Have fun...
 

Attachments

  • NHSocialShare.b4xlib
    1.2 KB · Views: 518
Last edited:

hatzisn

Expert
Licensed User
Longtime User
The social share library is now b4xlib
 

CaptKronos

Active Member
Licensed User
Longtime User
Is it possible to use this to post text to Facebook? I have tried:
B4X:
Social.ShareMessage("This is a trial message with a URL for Facebook   https://www.google.com", Social.Facebook)
and a post with a link to www.google.com is created but "This is a trial message with a URL for Facebook" is not shown. If I try:
B4X:
Social.ShareMessage("This is a trial message with a URL for Facebook", Social.Facebook)
then the Facebook post page is displayed but without any text entered.
 

hatzisn

Expert
Licensed User
Longtime User
It is not clear to me if you actually posted these messages to see how they behave.
 

CaptKronos

Active Member
Licensed User
Longtime User
More explicitly:
Call:
B4X:
Social.ShareMessage("This is a trial message with a URL for Facebook   https://www.google.com", Social.Facebook)
Facebook post page is displayed with the google link and I can click the Post button.

Call:
B4X:
Social.ShareMessage("This is a trial message with a URL for Facebook", Social.Facebook)
Facebook post page is displayed but because nothing has been entered to post, the Post button is greyed-out. So unless I type something manually, it is not possible to create a post.
 

hatzisn

Expert
Licensed User
Longtime User
If you post in the first case does it post only the link or the text too?
 

CaptKronos

Active Member
Licensed User
Longtime User
I have tried calling with more (multiple lines of) text and it is all ignored. The only way to have the Post button not greyed-out is if I include the url.
 

hatzisn

Expert
Licensed User
Longtime User
They must have changed something. I will google it and see what I can do. At the moment though I am very busy and it might take a while.
 
Top