B4J Question [abmaterial]This webapp is not running as a native app!

liulifeng77

Active Member
Licensed User
Longtime User
Hi,I'm interested in abm nativecontroller.

I copied the code to application page(in DEMO):

ABM.Native.Initialize("com.abmaterial.proj2102", "proj2102", "Manual Registration", "http://prd.one-two.com:51042/proj2102")

ABM.Native.VersionCode = "1"
ABM.Native.VersionName = ""
'ABM.Native.AndroidIcon72x72PngPath = "Z:/icon.png"
'ABM.Native.DesktopIcon256x256PngPath = "Z:/temp/icon.png"
ABM.Native.NoConnectionCancel = "Cancel"
ABM.Native.NoConnectionRetry = "Retry"
ABM.Native.NoConnectionMessage = "This application needs an internet connection!"
ABM.Native.QuitMessage = "Do you want to quit this application?"
ABM.Native.QuitYes = "Yes"
ABM.Native.QuitNo = "No"

' Do Not FORGET To DISABLE THIS LINE If YOU WANT To MAKE CHANGES To THE APPS!
'ABM.NativeGenerateApps(false)


and add the red line in the abmbuttonpage:

Sub btn1_Clicked(Target As String)
'If page.IsBlockedEvent("btn1_clicked") Then Return

page.NativeRequest("test")
If page.BlockEvent("btn1_clicked") Then Return
Dim myTexts, myReturns As List
myTexts.Initialize
myTexts.Add("READ IT")
myReturns.Initialize
myReturns.Add("READIT")
myToastId = myToastId + 1
page.ShowToastWithReturns("toast" & myToastId, "toast", "First raised button! (" & myToastId & ")", 5000, myTexts, myReturns)
page.UnblockEvent("btn1_Clicked")
End Sub


When clicked the button,
the log output:

NativePlatform:
This webapp is not running as a native app!


by the way, this line
'ABM.AppSetUseWebWorker(True)
appsetusewebworker is unkown member. why? it's for 3.05?
 

alwaysbusy

Expert
Licensed User
Longtime User
1. Page.NativeRequest("test") will never work. It needs a ABMControllerMessage converted to JSON (see the ABMNative.pdf document)
2. You'll get the message "This wepapp is not running as a native app" if you just open the app in your browser (like using http://localhost:51042/demo). You'll need to start the B4A app, and then click the button in the B4A app.
3. ABM.AppSetUseWebWorker(True): this was an experiment and will not be used as it does not work. I must have forgotten to remove it.
 
Upvote 0

liulifeng77

Active Member
Licensed User
Longtime User
I tried the demo proj2012
sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ABMaterialURL As String = "http://192.168.2.15:51041/sz" ' your app url

Dim NoConnectionTitle As String = "Manual Registration"
Dim NoConnectionMessage As String = "This application needs an internet connection!"
Dim NoConnectionRetry As String = "Retry"
Dim NoConnectionCancel As String = "Cancel"

Dim QuitTitle As String = "Manual Registration"
Dim QuitMessage As String = "Do you want to quit this application?"
Dim QuitYes As String = "Yes"
Dim QuitNo As String = "No"

Dim currentMessage As ABMControllerMessage
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 Viewer As WebView
Dim currentMessage As ABMControllerMessage
Dim controller As ABMController
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("ViewerLayout")

InitializeViewer
controller.Initialize(Viewer, Me)
Do While controller.IsOnline(ABMaterialURL) = False
Dim ret As Int = Msgbox2(NoConnectionMessage, NoConnectionTitle,NoConnectionRetry, "", NoConnectionCancel, Null)
If ret = DialogResponse.NEGATIVE Then
ExitApplication
End If
Loop
Viewer.LoadUrl(ABMaterialURL)
End Sub

Sub InitializeViewer
Viewer.Left = 0
Viewer.Top = 0
Viewer.Height = Activity.Height
Viewer.Width = Activity.Width
Viewer.ZoomEnabled = False
Viewer.Visible = True
End Sub


Sub Activity_Resume
InitializeViewer
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
Dim ret As Int = Msgbox2(QuitMessage, QuitTitle,QuitYes, "", QuitNo, Null)
If ret = DialogResponse.POSITIVE Then
ExitApplication
End If
Return True
End If
Return False
End Sub

Sub NativeRequest(jsonMessage As String) 'ignore
currentMessage.Initialize
currentMessage.FromJSON(jsonMessage)
Select Case currentMessage.Action

Case Else
currentMessage.Status=controller.STATUS_NORESPONSE
End Select
controller.NativeResponse(currentMessage.ToJSON)
End Sub

when clicked the button(in webpage)

Sub btn_do_clicked(target As String)

Dim command As ABMControllerMessage
command.Initialize
command.From="btn_do"
command.Target="camera"
command.Action="takepic"
page.NativeRequest(command.ToJSON)
end sub


server shows the message:This wepapp is not running as a native app.
something I missed?
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I'll check. Normally, when you run the B4A app, in the WebVeiw a variable with value "B4A" should be set. On the server side, this variable is then checked to see if it is really running in B4A.

Just for a test, can you also try running the generated B4J app and see if this problem is the same? (It should set the variable to "B4J")
 
Upvote 0

liulifeng77

Active Member
Licensed User
Longtime User
it's OK!
but if runing in release mode,controller.IsOnline(ABMaterialURL) will be false. in debug mode will not.o_O
 
Upvote 0
Top