Android Question OkHttp - Set parameter with Inline Java

M. Giray Ozkan

Member
Licensed User
Longtime User
Hello,

I'm using OkHttp and OkHttpUtils library and I trying to customize OkhttpUtils library. I need to run createPing sub in inline java code. is there any way to pass "hc" object (Private hc As OkHttpClient) to this sub?

B4X:
Sub Process_Globals
    Private hc As OkHttpClient
    Private jo As JavaObject
    Private johc As JavaObject
    Private TaskIdToJob As Map
    Public TempFolder As String
    Private taskCounter As Int
   
End Sub

Sub Service_Create
    TempFolder = File.DirInternalCache
    hc.Initialize("hc")
    TaskIdToJob.Initialize
   
    jo.InitializeContext
    johc = hc
   
    jo.RunMethod("createPins", johc)

End Sub

is return java.lang.ClassCastException: anywheresoftware.b4h.okhttp.OkHttpClientWrapper cannot be cast to java.lang.Object[] error

B4X:
#if java


import android.content.Context;
import android.util.Log;

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.CertificatePinner;

import java.io.InputStream;
import java.io.Reader;
import java.security.KeyStore;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;


    public void createPins(OkHttpClient client) {
        try {

            client.setCertificatePinner(new CertificatePinner.Builder()
                   .add("abcdefg.com", "sha1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
                   .add("abcdefg.com", "sha1/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")
                   .build());
  

        } catch (Exception e) {
            BA.Log(e.getMessage());

        }
    }


#end if
 
Top