Android Question [Solved]How detect the Thai developer create app by B4XPages ,or not?

Theera

Well-Known Member
Licensed User
Longtime User
Refer to this (one of the part ThaiUtils B4xLib) How to code for detecting each Thai developer selects app by B4XPages?
 
Solution
Let me explain again, because I created a library. ThaiUtils.b4xlib came up, but it's hard to know if the app developer created it with B4XPages or built it the traditional way. Assuming the developer chooses to build it in the same way, the error I have shown in the picture will occur.Therefore, I have to write a library that can support both methods, but I don't know how to write it.

Maybe try calling a B4XPages method that will fail if B4XPages is not initialized, or something like this:

B4X:
Sub UsesB4XPages As Boolean
    Dim ReturnValue As Boolean = False
    
    Try
        If B4XPages.Initialized Then
            ReturnValue = True
        End If
        
    Catch
        ReturnValue = False    'to be sure, to be sure...

PaulMeuris

Well-Known Member
Licensed User
Just to state the obvious...
A B4XPages app has at least a method called B4XPage_Created (Root1 As B4XView) in the B4XMainPage module and the main module uses a B4XPagesManager.
The B4XPagesManager gets initialized with an Activity in B4A or with a Form (MainForm) in B4J.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
It should have the command ,or not?
B4X:
#If B4XPages  Then
#else
#End If

I 'have tried to create app as default (Not-B4XPages) ,it has error code as picture (If done in B4XPages,it worked)
 

Attachments

  • error.png
    error.png
    5.3 KB · Views: 40
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
The error is in the B4XThaiUtils code where the JavaObject type is unknown.
Did you include the JavaObject library in that B4XThaiUtils code?
I only tested the bas file. Testing with B4XPages went well, but when using Not-B4XPages, it gave an error.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
If it is a standard Activity (not B4XPages) then it should be
Dim twb as JavaObject
twb.initializeContext

Not sure how you are using it and I might be wrong.

It was explained in the other similar thread that you posted and was answered/commented on by numerous members.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
If it is a standard Activity (not B4XPages) then it should be
Dim twb as JavaObject
twb.initializeContext

Not sure how you are using it and I might be wrong.

It was explained in the other similar thread that you posted and was answered/commented on by numerous members.
Let me explain again, because I created a library. ThaiUtils.b4xlib came up, but it's hard to know if the app developer created it with B4XPages or built it the traditional way. Assuming the developer chooses to build it in the same way, the error I have shown in the picture will occur.Therefore, I have to write a library that can support both methods, but I don't know how to write it.
 
Upvote 0

emexes

Expert
Licensed User
Let me explain again, because I created a library. ThaiUtils.b4xlib came up, but it's hard to know if the app developer created it with B4XPages or built it the traditional way. Assuming the developer chooses to build it in the same way, the error I have shown in the picture will occur.Therefore, I have to write a library that can support both methods, but I don't know how to write it.

Maybe try calling a B4XPages method that will fail if B4XPages is not initialized, or something like this:

B4X:
Sub UsesB4XPages As Boolean
    Dim ReturnValue As Boolean = False
    
    Try
        If B4XPages.Initialized Then
            ReturnValue = True
        End If
        
    Catch
        ReturnValue = False    'to be sure, to be sure
    
    End Try
    
    '''Log("UsesB4XPages = " & ReturnValue)
    
    Return ReturnValue
End Sub
 
Upvote 0
Solution

emexes

Expert
Licensed User
Or you might have to use CallSub and a WaitFor, see if it comes back with (B4XPages) object not found or similar.

There might be a "problem" that presumably your library also uses B4XPages code for when the library user is using B4XPages, and that might be enough to trick us your library into always thinking that the library user is using B4XPages.

Worst case, but probably safest and simplest solution, might be to have two versions of the library: ThaiUtils.b4xlib and ThaiUtilsB4XPages.b4xlib
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I 've test using Try.. Catch.. End Try , it can be solved. , I don't use B4XPages because
it is known only in B4XPages solution. Thank you, Emexes.
 
Upvote 0
Top