B4A Library Licensing library

Informatix

Expert
Licensed User
Longtime User
EDIT: Ah OK, I understand now. I have to declare my global variable in the main activity and nowhere else, and SetVariableAndValue will modify this variable even if I call the function in another activity. It was not obvious.
 
Last edited:

Kevin

Well-Known Member
Licensed User
Longtime User
I've been putting off adding this to my app for various reasons, but one of the biggest was uncertainty about potential problems with Amazon. Primarily the only difference in my code between Google Play and Amazon is the market links for my other apps, which is controlled by a variable.

If I add this to my project, will it run fine on an Amazon-only device such as a Kindle Fire if I were to skip any licensing code, or will it not run at all if it references a package (licensing package) that may not even exist on the device?

The way I see it, I have two choices:

  1. Skip (bypass) the license checking code if the app has the "Amazon" variable set. This idea will only work if the app will run okay with a missing referenced package so long as I do not attempt to "call" it. This seems most logical and foolproof since it would also prevent invalid license results on a normal Android device where the user purchased my app through the Amazon Appstore app rather than Google Play. Certainly one could "hack" the app and change the variable but anything, including the licensing scheme, can be hacked or bypassed.

  2. Maintain two separate B4A projects and code sets for my app, which I really don't want to do.

Has anyone published an app on Google Play (using licensing) and Amazon using the same "base" B4A code? I suspect #1 will work but I don't want to go through the trouble of adding and testing it only to have Amazon reject it because it fails on an Amazon-only device.
 

peacemaker

Expert
Licensed User
Longtime User
I had the same choice before and... decided to forget Amazon. Maybe wrongly...
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Kevin, they will probably reject your app when you upload it. Amazon tests the APK for incompatible APIs.

I believe that in the future we will have support for conditional compilation which will make it simpler. For now you can try to convert the core of your app to a library and then reference this library from two different projects.
 

Kevin

Well-Known Member
Licensed User
Longtime User
I believe that in the future we will have support for conditional compilation which will make it simpler.

Excellent news... my biggest wish! Assuming we do get conditional compilation, will referenced libraries be conditional as well? Otherwise I don't know that conditional compilation would work in this particular case if only sections of code itself would be conditional; i.e. the app would still reference an API that is not available on an Amazon device.
 

FabioG

Active Member
Licensed User
Longtime User
I have problems with this library
I use it for a long time

many users after have purchased the app from Google Play me point out that often
can not use the application because they receive the message of having to pay the app

it is as if the lib did not do the job

in practice it seems that the license check fails
sometimes you need to uninstall the app to restart the device and reinstall the app

this is the code that I use

how can I fix it?

B4X:
Sub Process_Globals

Dim publicKey As String
publicKey = "MIIBI....."
Dim myvar_1 As String

End Sub


Sub Activity_Create(FirstTime As Boolean)

   Dim lc As LicenseChecker   
   lc.Initialize("lc", GetDeviceId, publicKey, "asj...".GetBytes("UTF8"))
   lc.SetVariableAndValue("myvar_1", "MyValue")
   lc.CheckAccess

End Sub

Sub lc_Allow
    Log("Licensed")
    ToggleButton_Enable.Enabled = True
End Sub

Sub lc_DontAllow
  Log("License: DontAllow")
  ToggleButton_Enable.Enabled = False
    Msgbox(TxTNoLicense,AppName)
End Sub

Sub lc_Error (ErrorCode As String)
  Log("License error: " & ErrorCode)
    Msgbox(TxTNoLicense & " " & ErrorCode,AppName)
  ToggleButton_Enable.Enabled = False
End Sub

Sub GetDeviceId As String
    Dim R As Reflector
    Dim Api As Int
    Api = R.GetStaticField("android.os.Build$VERSION", "SDK_INT")
    If Api < 9 Then
        'Old device
        If File.Exists(File.DirInternal, "__id") Then
            Return File.ReadString(File.DirInternal, "__id")
        Else
            Dim id As Int
            id = Rnd(0x10000000, 0x7FFFFFFF)
            File.WriteString(File.DirInternal, "__id", id)
            Return id
        End If
    Else
        'New device
        Return R.GetStaticField("android.os.Build", "SERIAL")
    End If
End Sub
 

FabioG

Active Member
Licensed User
Longtime User
Seems like an issue with this service: https://code.google.com/p/marketlicensing/issues/detail?id=44

Note that it is recommended to only check the license when FirstTime is True.

Hello Erel

I still have a lot of complaints from many users
and I'm also getting bad reviews for this problem

I found this solution: http://androidforums.com/application-development/154625-licensing-always-denies-caching-issue.html

You can modify the library Licensing?

Thanks very mutch
Fabio
 

FabioG

Active Member
Licensed User
Longtime User
B4A licensing library is based on a different policy (the recommended one): ServerManagedPolicy

sorry Erel, I'm lost
I need some practical advice or an example
I am receiving several complaints
 

FabioG

Active Member
Licensed User
Longtime User
Sorry but it seems to be an issue with Google server. If they can provide you with any more information then it might be useful.
Thanks Erel
But it is strange, when I purchasing other app from Google Play this does not happen
 

MarcTG

Active Member
Licensed User
Longtime User
Hello,

I've been looking at this thread and at the tutorial thread, and it seems many people have had issues implementing this library for various reasons. While looking at the tutorial thread on page 8 (http://www.b4x.com/android/forum/th...ation-with-the-licensing-library.11429/page-8) yttrium mentioned that this library is not required if only developing for API >=16.

API >=16 currently represents 78.3% of devices according to Google (https://developer.android.com/about/dashboards/index.html) and this number will obviously keep increasing... Say that I am satisfied having my app only available to that 78.3% of users, is it enough to just set the minimum API in the manifest to 16 to avoid using this library and still have a paid app secure?

I am just asking this to confirm and inform anyone else who is considering using this library.

Thanks
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…