Other Is possible to force the use of HTTPS?

beachner

Member
I'm currently trying to create a wrapper for a mapping sdk from Mapfactor and I'm having trouble with the activation of the library.
When I'm running the activation code through my wrapper in B4A I get an error saying that Cleartext HTTP traffic to mapfactor.com not permitted. This message does not appear when I use the library in a project created with Android Studio.

This is the code in the wrapper library that I'm calling from B4A.

ActivateDevice:
public void ActivateDevice(BA ba){
        this.ba = ba;
      
        ActivationListener listener = new ActivationListener() {

            @Override
            public void onActivationFinished(ActivationResult activationResult) {
                boolean succeeded = activationResult == MpfcEngine.ActivationResult.SUCCEEDED || activationResult == MpfcEngine.ActivationResult.ALREADY_ACTIVATED;
                ba.raiseEventFromUI(this, "onActivationResult".toLowerCase(BA.cul)+"_fire", succeeded);
                Log.d("MpfcEngine", "Activationresult is " + succeeded);
              
            }
          
        };
      
        MpfcEngine.getInstance().activateDevice("<Some API-key>", listener);
    }

I instatiates the wrapper in Activity_Create
Activity_Create:
Sub Activity_Create(FirstTime As Boolean)
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim engine As JavaObject
    engine.InitializeNewInstance("com.company.mapfactorwrapper.MpfcEngineWrapper",Null)
    mmpfcEngine = engine
    Dim path = rp.GetAllSafeDirsExternal("")(0) As String
    mmpfcEngine.InitTomTom(ctxt,path,mmpfcEngine.ENGLISH_US)

    Activity.LoadLayout("Layout") 
End Sub

and I call the activation logic from a event callback when the library failes to initiate
onEngineInitFinished_Fire:
Sub onEngineInitFinished_Fire(result As Int)
    xui.MsgboxAsync(result,"onEngineInitFinished")
    If result = mmpfcEngine.SUCCESS Then
        Private MapView1 As MapView
      
        Panel1.AddView(MapView1,0,0,Panel1.Width,Panel1.Height)
    Else
        mmpfcEngine.ActivateDevice()
    End If
End Sub

the mmpfcEngine variable is declared in Process_Globals

Process_Globals:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Public mmpfcEngine As MpfcEngineWrapper
    Public rp As RuntimePermissions
End Sub

I've tried adding

SetApplicationAttribute(android:usesCleartextTraffic, "false")

to the manifest without effect

Any help you could give me would be appreciated.

Edit: Never mind,
SetApplicationAttribute(android:usesCleartextTraffic, "false")
should of courde been set to true. Don't no why I didn't have to add it to the Android Studio project. Sorry.
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
You can add in manifest this:
B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)
or
B4X:
SetApplicationAttribute(android:usesCleartextTraffic, "true")
they are the same thing
 

beachner

Member
Thank you, the problem was that for some reason I got it in my head that it was the licencing server for map sdk that was throwing this error and not the Android runtime.
As soon as I added
B4X:
SetApplicationAttribute(android:usesCleartextTraffic, "true")
that bit worked fine. Could have been more clear about that in my edit. Sorry about that but thanks again for your help:)
 

DonManfred

Expert
Licensed User
Longtime User
Allowing the use of http is not the same as forcing to use https!

In fact with
B4X:
android:usesCleartextTraffic, "true"
you are explicitely allowing http-use.

You should not use that setting and REALLY use only https.
 

beachner

Member
Allowing the use of http is not the same as forcing to use https!

Yes, that is true. And a good point. But at the moment I'm just trying to get it to work and I don't know what's on the other end of the pipe. Does the licensing server support HTTPS? If I can get the sdk to work at all in this framework I would be very happy. Then I can look into that bit further down the line, but at the moment I would be happy if I just could get it to work at all.
 
Top