Building libraries for external SDK's

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

There are a lot of external API's popping up and I would love to develop some libraries for it. Does anyone have source code for a sample library based on an external SDK? Maybe the Xtify demo or something else?

Building libraries for these SDK's would rapidly extend B4A and I think that is needed. Re-inventing the wheel is waste of time, I rather use what is proven.

Cheers,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here is the code of the Google Analytics library (without the javadocs):
B4X:
package anywheresoftware.b4a.objects;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.keywords.Common;

@Version(1.0f)
@ShortName("AnalyticsTracker")
@Permissions(values={"android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE"})
public class AnalyticsTracker {

   public void Initialize(String AccountId, int DispatchPeriod) {
      GoogleAnalyticsTracker.getInstance().startNewSession(AccountId, DispatchPeriod, BA.applicationContext);
   }

   public void Initialize2(String AccountId) {
      GoogleAnalyticsTracker.getInstance().startNewSession(AccountId, BA.applicationContext);
   }

   public void TrackPageView(String Page) {
      GoogleAnalyticsTracker.getInstance().trackPageView(Page);
   }

   public void TrackEvent(String Category, String Action, String Label, int Value) {
      GoogleAnalyticsTracker.getInstance().trackEvent(Category, Action, Label, Value);
   }

   public boolean Dispatch() {
      return GoogleAnalyticsTracker.getInstance().dispatch();
   }

   public void Stop() {
      GoogleAnalyticsTracker.getInstance().stopSession();
   }
}

The trick is to create an empty XML file for the wrapped library (libGoogleAnalytics.xml):
B4X:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <doclet-version-NOT-library-version>1.00</doclet-version-NOT-library-version>
    <version>1.0</version>
</root>
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I cannot export the complete project. Sorry. However it is a really simple one:

SS-2011-10-26_10.55.02.png
 
Upvote 0

avacondios

Active Member
Licensed User
Longtime User
Hi Erel,

I am trying to execute this example, but I am getting errors when I am executing the application that it cannot find the libGoogleAnalytic.jar. Can you explain to us, where we need to copy the external jar files which we have already referenced to eclipse ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am trying to execute this example, but I am getting errors when I am executing the application that it cannot find the libGoogleAnalytic.jar. Can you explain to us, where we need to copy the external jar files which we have already referenced to eclipse ?
Are you trying to build a library or to use the existing one?
 
Upvote 0

avacondios

Active Member
Licensed User
Longtime User
Hi Erel,

I tried to use reference library from eclipse. The issue was that I did not used the statement @DependsOn(values={"library name") !!!!, so I had exception that the application cannot find the library. At least I found that.

Thanks a lot
 
Upvote 0
Top