B4A Library [BETA] ahaShareLibrary

[LIB] [B4A SourceCode] ahaShareLibrary

Hi!

As we all have the Problems with sharing Text/Pictures via Intents and Facebook, I decided to write a small library that get rid of this Problem. It's very easy to use and takes all the work away from you :)

You can share Text, Pictures, Documents.....



It's still beta, so please report any Bugs/Wishes.

Usage is very simple:
B4X:
Dim Share as ahaShare
Share.initialize(Me, "Share")
Share.FaceBookAppID = "xxxx"
Share.FaceBookRedirectUri = "http://www.xxxxxx.xxx/"
Share.Share("Test-Subject","Test-Text")
After sharing, the Finished Event is called
B4X:
Sub Share_Finished
   ..your code here
End Sub
Screenshot :
attachment.php


PS: As you can see you can customize nearly everything:
attachment.php
attachment.php
attachment.php



This library is written in B4A :)

I hope you like it :)
  • ahaShare
    Methods:
    • IsInitialized As Boolean
      Tests whether the object has been initialized.
    • Addfile (Directory As String, Filename As String) As String
      Adds a file to the Intent
      <B>Attention: file.DirAssets and file.dirInternal will <I>NOT></I> work as Directory!!</B>
    • Addpackagefilter (PackageFilter As String) As String
      Adds a packagefilter. Packages with the given names will not be shown in the ContentChooser
      Example1: "com.google.android.keep" to hide Google Keep from the choosable Apps
      Example2: "synology" hides every Synology-App
    • Clearfiles As String
      Clears all added files
    • Initialize (Module As Object, EventName As String) As String
      Initializes the Library

      <B>Normal Library usage:</B>
      -----------------------
      <code>Dim Share as ahaShare
      Share.initialize(me, "Share")
      Share.FaceBookAppID = "xxxx"
      Share.FaceBookRedirectUri = "http://www.xxxxxx.xxx/"
      Share.Share("Test-Subject","Test-Text")</code>

      Event Finished will be raised when Sharing is finished:
      Sub Share_Finished
      ..your code here (i.e deleting temp files,...)
      End Sub

      <B>That's it :)</B>
    • Sshare (Subject As String, Text As String) As String
      Starts the ContentChooser
    Properties:
    • buttonnormalcolor As Int
      Color of the unpressed Buttons
      Standard: colors.white
    • buttonpressedcolor As Int
      Color of the pressed Button
      Standard: Colors.RGB(29,162,235)
    • cornerradius As Int
      Corner radius of the Buttons
    • facebookappid As String
      Your Facebook AppID. Needed for publishing to FaceBook.
      Tutorial by NJDude: <link>http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html|http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html</link>
      Attention: If not set, FaceBook will not be available to share with
    • facebookredirecturi As String
      Your Facebook RedirectUri. Needed for publishing to FaceBook.
      Tutorial by NJDude: <link>http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html|http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/17739-tutorial-post-facebook-wall-via-b4a-app.html</link>
      Attention: If not set, FaceBook will not be available to share with
    • headerbackcolor As Int
      BackColor of the Header
      Standard: Colors.Transparent
    • headertext As String
      HeaderText of the ContentChooser
      Standard: Choose
    • headertextcolor As Int
      TextColor of the Header
      Standard: Colors.RGB(49,182,255)
    • headertextsize As Int
      TextSize of the Header
      Standard: 22
    • intenttype As String
      IntentType, for example "text/*" for Text, "image/jpeg" for jpg, "image/png" for png etc..
    • linecolor As Int
      Color of the Seperatorline below the Header
      Standard: Colors.RGB(49,182,255)
    • padding As Int
      Padding
      Standard: 10dip
    • panelcolor As Int
      Color of the ContentChooser Panel
      Standard: Colors.white
    • sendingtofacebookfinishedstring As String
      The String displayed as ToastMessage after Sending to Facebook succeeded
      Standard: "Posted to Facebook"
    • sendingtofacebookstring As String
      The String displayed in the ProgressDialog while sending to FaceBook
      Standard: "Posting to Facebook..."
    • shadowcolor As Int
      Color of the Background Shadow.
      Use colors.rgb(x,x,x) for opaque background, colors.argb(x,x,x,x) for Transparency
      Standard: Colors.ARGB(150,0,0,0)
    • subject As String
      Subject (for E-Mail,..) set as android.intent.extra.SUBJECT
    • text As String
      The Message. Set as android.intent.extra.TEXT
    • textcolor As Int
      Textcolor of the Names of the displayed Packages
      Standard: Colors.Black
    • textsize As Int
      TextSize of the Names of the displayed Packages.
      Standard: 14
    • AppButtonWidth As Int
      Width of the Buttons
      Standard: 160dip
    • AppButtonHeight As Int
      Height of the Buttons
      Standard: 120dip
    • AppIconSize As Int
      Size of the Images on the Buttons
      Standard: 48dip
    • HeaderHeight As Int
      Height of the Header
      Standard: 60dip
Generated with Warwounds Library reference generator
---------------
Version 0.6
New:
_Finished Event added

Version 0.7
New:
Long click on the App-Symbol opens the Android Application Settings for the clicked app (as the original contentchooser
Fixed: Last line of Icons was not displayed. (Thanks to derez!!)
Change: More icons are displayed at once (Height of the Buttons reduced)

Version 0.8
New:
AppButtonWidth: sets the width of the Buttons
AppButtonHeight: sets the height of the Buttons
AppIconSize: Sets width & height of the AppIcons
HeaderHeight: Sets the height of the Header
Fixed: Error handling in all Subs

Version 1.0
Beta finished :)
SourceCode attached
 

Attachments

  • Example.zip
    42.3 KB · Views: 511
  • Screenshot.png
    Screenshot.png
    45.6 KB · Views: 1,299
  • Screenshot2.png
    Screenshot2.png
    30.6 KB · Views: 1,274
  • ScreenshotXS.png
    ScreenshotXS.png
    25.1 KB · Views: 1,208
  • ScreenshotS.png
    ScreenshotS.png
    33.7 KB · Views: 1,208
  • ahaShareLibrary.zip
    22.1 KB · Views: 525
  • ahaShareSource.zip
    126.2 KB · Views: 402
Last edited:

Jack Cole

Well-Known Member
Licensed User
This library is very useful. I am experiencing a problem with Facebook shares. What happens is that after tapping facebook in the chooser, the facebook login screen pops up very briefly and it immediately switches back to the chooser screen. There are no errors showing in the logs. I have tried it on two different devices, so it is not a device specific problem. Any ideas?
 

Fox

Active Member
Licensed User
Thats the same problem here... I have tried to work with panels but without success. A solution for this problem would be great. I have an Samsung Galaxy S4 and the other devices where i have tried it was Archos 70 Tablet the next was an xperia pro and an htc desire everytime the same effect.
 

Creaky

Member
Licensed User
I experience this problem on my S4 as well.
Hopefully it can be fixed as I'm really looking forward to use this lib to post stuff to Facebook! :D
 

Creaky

Member
Licensed User
Unfortunately there is still no reply from RiverRaid. I've tried contacting him through a conversation, but without luck.
 

Creaky

Member
Licensed User
I've been looking through the source of this library and noticed that the problem is not with the library itself.

It only displays the Facebook login if all of Facebooks oAuth requirements are met.

B4X:
Private Sub Share
    If FBAccessToken = "" Then
        Dim scope As String
        scope = "publish_stream"
        FacebookPage.Visible = True
        FacebookPage.LoadUrl("https://m.facebook.com/dialog/oauth?client_id=" & mFaceBookAppID & "&redirect_uri=" & mFaceBookRedirectUri & "&scope=" & scope & "&response_type=token")                   
    Else
        PostWall
    End If
End Sub

Sub FacebookPage_PageFinished(Url As String)
    FacebookPage.Visible = False '<-- This is where the facebook login disappears
    If Url.StartsWith("http://m.facebook.com/login.php") Then
        ProgressDialogHide
        FacebookPage.Visible = True
    End If

    If Url.StartsWith(mFaceBookRedirectUri & "#access_token=") Then
        FacebookPage.Visible = False
        FBAccessToken = Url.SubString((mFaceBookRedirectUri & "#access_token=").Length)
        FBAccessToken = FBAccessToken.SubString2(0, FBAccessToken.IndexOf("&"))
        PostWall
    End If
End Sub

In my case, the URL I passed was not configured in the FB webapp settings.

To see what is going wrong in your app, try the following URL:

https://m.facebook.com/dialog/oauth...Uri>&scope=publish_stream&response_type=token

Even with this info I have not managed to succesfully post to FB because I don't have one of the following:

(translated from dutch)
  • Website with facebook login
  • App on Facebook
  • Native iOS-app
  • Native Android-app
  • Page-tab
It appears that this library will never open the local Facebook app through an intent or otherwise..
But perhaps somebody else could have a look at the sourcecode to verify this? (Erel?)
 

mhartwig

Member
Licensed User
I get the following error:

B4X:
facebook.FaceBookAppID = \
javac 1.6.0
src\com\gasmeup\main\main.java:403: cannot find symbol
symbol  : method set_facebookappid(java.lang.String)
location: class at.ahadev.b4a.ahashare.ahashare
_facebook.set_facebookappid("***************");
 

Watchkido1

Active Member
Licensed User
I have too many icons.
How do I get away?
 

Attachments

  • Screenshot.png
    Screenshot.png
    208.9 KB · Views: 76

Sub7

Active Member
Licensed User
Bump!
When i try to use the share button for Facebook the Facebook login screen appears but then it disappear with no errors and nothing happen.
anyone has managed to make this work? i see other people had this problem.

Ty
 

MarcoRome

Expert
Licensed User
Hi all.
when i try example in attachment ( 1 page ) all work but if i try share this with Whatsapp i see only Text without picture.

B4X:
Share.Initialize(Me, "Share")
 'Share.FaceBookAppID = "xxxx"
 'Share.FaceBookRedirectUri = "http://www.xxxxxx.xxx/"
 
    Share.HeaderText = "Condividi XXXX: "
    File.Copy(File.DirAssets,"post2.jpg",File.DirRootExternal,"post2.jpg")
    Share.AddFile(File.DirRootExternal,"post2.jpg")
    'Share.Share("This is the Subject","This is the Text")
    Share.Share("Test AhaShare",CRLF & "Facciamo questo Test" & CRLF & _
        "**********************" & CRLF & _
        "Inviato da App Barzellette: " & CRLF & _
        https://play.google.com/store/apps/details?id=com.xxxx & CRLF & _
        http://www.xxxxx.eu)

Any idea ??
Thank you

Marco
 

ibra939

Active Member
Licensed User
thanks for sharing option :rolleyes::);)
 

MarcoRome

Expert
Licensed User
Bump!
When i try to use the share button for Facebook the Facebook login screen appears but then it disappear with no errors and nothing happen.
anyone has managed to make this work? i see other people had this problem.

Ty

Yes..me too have this effect. Also i connect with FB.
If you touch again top icon FB share in fast mode you see this:

ahashare1.png


and you click "Scarica Facebook per Android e naviga più velocemente" you see this:

ahashare2.png


So i think that FB change one thing and AhaShare dont pubblish....
 

Kiese

Member
Licensed User
Hi everyone. First of all, thanks for the lib. Seems promising. However I can't get it to work, even using the provided example, I get this in the logs:

** Activity (ahacontentchooser) Create, isFirst = true **
** Activity (ahacontentchooser) Create, isFirst = true **
java.lang.RuntimeException: Object should first be initialized (Activity).java.lang.Runtime
Exception: Object should first be initialized (Activity).

How could I fix this?
 

Kiese

Member
Licensed User
Wow been so long that I forgot about my question. Am I the only one facing this issue or is the lib deprecated ?
 

juan manuel luzuriaga

Member
Licensed User
Kiese, I have the same problem.

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (ahacontentchooser) Create, isFirst = true **
java.lang.RuntimeException: Object should first be initialized (Activity).
** Activity (ahacontentchooser) Resume **

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Share As ahaShare
    Private Button1 As Button
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")
   

    File.Copy(File.DirAssets,"post2.jpg",File.DirRootExternal,"post2.jpg")
    Share.Initialize(Me, "Share")
    'Share.AddFile(File.DirRootExternal,"post2.jpg")
    'Share.Share("This is the Subject","This is the Text")
       
End Sub
Sub Share_Finished
    Activity.Title = "finished"
    File.Delete(File.DirRootExternal,"post2.jpg")
End Sub
Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Button1_Click

    Share.AddFile(File.DirRootExternal,"post2.jpg")
    Share.Share("This is the Subject","This is the Text")
End Sub

I got the same error, form the example.

Do you find any solution?
 

MarcoRome

Expert
Licensed User
Kiese, I have the same problem.

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (ahacontentchooser) Create, isFirst = true **
java.lang.RuntimeException: Object should first be initialized (Activity).
** Activity (ahacontentchooser) Resume **

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Share As ahaShare
    Private Button1 As Button
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")
  

    File.Copy(File.DirAssets,"post2.jpg",File.DirRootExternal,"post2.jpg")
    Share.Initialize(Me, "Share")
    'Share.AddFile(File.DirRootExternal,"post2.jpg")
    'Share.Share("This is the Subject","This is the Text")
      
End Sub
Sub Share_Finished
    Activity.Title = "finished"
    File.Delete(File.DirRootExternal,"post2.jpg")
End Sub
Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Button1_Click

    Share.AddFile(File.DirRootExternal,"post2.jpg")
    Share.Share("This is the Subject","This is the Text")
End Sub

I got the same error, form the example.

Do you find any solution?
maybe if attachment example is better
 

MarcoRome

Expert
Licensed User
Kiese, I have the same problem.

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (ahacontentchooser) Create, isFirst = true **
java.lang.RuntimeException: Object should first be initialized (Activity).
** Activity (ahacontentchooser) Resume **

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Share As ahaShare
    Private Button1 As Button
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")
  

    File.Copy(File.DirAssets,"post2.jpg",File.DirRootExternal,"post2.jpg")
    Share.Initialize(Me, "Share")
    'Share.AddFile(File.DirRootExternal,"post2.jpg")
    'Share.Share("This is the Subject","This is the Text")
      
End Sub
Sub Share_Finished
    Activity.Title = "finished"
    File.Delete(File.DirRootExternal,"post2.jpg")
End Sub
Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Button1_Click

    Share.AddFile(File.DirRootExternal,"post2.jpg")
    Share.Share("This is the Subject","This is the Text")
End Sub

I got the same error, form the example.

Do you find any solution?

I havent problem with your source.



I use B4A 6.31 + android-23
 

juan manuel luzuriaga

Member
Licensed User
WOW, I try with B4A 6.30 and now 6.50 both give me the same failure. My android It is 24
OK I will try again.

Thanks you so much
 
Last edited:
Top