Licensing Library

straybullet

Member
Licensed User
Longtime User
My tests APPS are always reported as LICENSED, when the console is set to NOT_LICENSED. I have uploaded the test app, but not published it.

This isn't the entire app, but I stripped out enough to show what I am doing to see if some one can locate what I am missing. I always get licensed passed (my toast message) when testing the app on real devices. Any help will be greatly appreciated


B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim WebView1 As WebView
   Dim ph As Phone
    Dim bd As BitmapDrawable
   
   '*************************************
   'license setup
   Dim publicKey As String
   'shortened public key for posting - real key goes below
        publicKey = "MIIBIjANBgkqhkiG9w0BAQ"
        Dim test1 As String
   Dim ptype As String
   ptype = ph.Model
   'end license setup
   '*************************************
   
End Sub

Sub Activity_Create(FirstTime As Boolean)


'*************************************
' Begin licensing code
 If FirstTime Then
        Dim lc As LicenseChecker
        Dim p As PhoneId
      lc.Initialize("lc", p.GetDeviceId, publicKey, "kljdflkf".GetBytes("UTF8"))
        lc.SetVariableAndValue("test1", "randomstring")
      If ptype = "sdk" Then
      ToastMessageShow("SDK Detected", True)
        'emulator -> jump to Allow
           lc_Allow
         Else
        'check license
            lc.CheckAccess
           End If
    End If   
' End licensing code
'*************************************


Dim url As String
Activity.LoadLayout("Main")

'*************************************
'Start load and view - load index screen
WebView1.Initialize("WebView1")

Activity.AddView(WebView1,0dip, 0dip, 100%x, 100%y)

url="file:///android_asset/index.html"

WebView1.LoadUrl(url)
'End load code 
'*************************************

End Sub

Sub Activity_Resume

End Sub


Sub WebView1_OverrideUrl (Url As String) As Boolean
    
   '*************************************
   'Intercepted market request
   If Url.IndexOf("market://")>-1 Then
       WebView1.StopLoading
      Dim market As Intent
      market.Initialize(market.ACTION_VIEW,Url)
      StartActivity (market)
    End If
   '*************************************

   
   
End Sub


Sub lc_Allow
'licensed passed
    ToastMessageShow("License Passed.", True)
    Log("Allow")
End Sub

Sub lc_DontAllow
'failed license check
    Log("DontAllow")
    ToastMessageShow("Invalid License.", True)
    Activity.Finish
End Sub

Sub lc_Error (ErrorCode As String)
'error checking license
    Log("error: " & ErrorCode)
    ToastMessageShow("License Error.", True)
    Activity.Finish
End Sub
 
Last edited:

straybullet

Member
Licensed User
Longtime User
Erel, not sure how my phones and tablets would be listed as sdk, I added that so I could test out the app in the emulator. I will have toast show me ptype, any thing else look like it could be an issue to you?

Update: The ptype is correctly reporting the phone name, so its not that :(
 
Last edited:
Upvote 0

straybullet

Member
Licensed User
Longtime User
Thanks for the help so far, but still getting the same results. I cleared the cache before I posted, I should have mentioned that. I have cleared the cache and uninstalled the app a few times. Even powered off the device, but still says license passed when I run the app which is connected to the internet.


Erel did not mention anything was wrong in the code, but double check the ptype which I did and that is not sdk, it is the phones name which makes it run the license check.

I moved load layout into the allowed sub as suggested, but that is not the license issue just a smart thing to do.

So I am at a lost why license library is not working for me, I was really hoping to get this going soon.


Again thanks for the help, if anyone else has suggestions please share them.
 
Upvote 0

straybullet

Member
Licensed User
Longtime User
Well found the issue, I had to format a phone and setup the Android Developer account as the main account on the phone. Although all the accounts on the phone were test accounts, and the developer account was on the phone, it did not matter.

So for future reference in order to test this you must be using the Developer Account as your main phone account.

Hopefully this will save someone a lot of headache knowing this.

Good thing I have 6 test devices (Tablets and phones)
 
Upvote 0

straybullet

Member
Licensed User
Longtime User
OK got the licensing working, but now when I change the orientation (by rotating the phone) or leave the program via the home key and try returning to it, I get a black screen.

I assume this is because the program is resuming and not running the first time function, how do I handle this resume since my load layout has been moved in to the lc_allow as suggested by Erel?

Is there an easier way than coping everything from layout from the lc_allow in to the resume sub?


Update: I decided to move the load loadout back in the first time sub, because now I use timers if the license fails, it shows a message then kills the app after 3 secs, so not much they can do in 3 seconds.
 
Last edited:
Upvote 0
Top