1

I am new to Codenameone , I am having strange issue in Codenameone's ConnectionRequest API while fetching response from https site in google pixel device in which anroid 10 is installed. fetching from https site is working fine.

However in the simulator it is fine and also with the other device that has android less than version 10.

what could be the solution for this OR am i doing somthing worng?

Here is my code and error i am getting in device

First Tried :

 TextArea resultTextArea = new TextArea();
    Button download = new Button("RUN");

    download.addActionListener((e) -> {
        ConnectionRequest cr = new ConnectionRequest(url, false);
        SliderBridge.bindProgress(cr, progress);
        NetworkManager.getInstance().addToQueueAndWait(cr);
        if (cr.getResponseCode() == 200) {

            String resultString = "";


            try {

                byte[] initialArray = cr.getResponseData();
                resultString = new String(initialArray);

                resultTextArea.setText(resultString);
            } catch (Exception eee) {
                resultString = "Error => " + resultString + eee.getMessage();
            }

            System.out.println(resultString);
        }
    });

Second Try: where url = http://192.168.2.100:8084/semms-webservice/rest/device/test/users

public void testURLConnectionResponse(String url) {
    ConnectionRequest request = new ConnectionRequest();
    request.setContentType("application/json");
    request.setUrl(url);
    request.setHttpMethod("GET");

    TextArea resultTextArea = new TextArea();
    String result = "";

    result = "RESPONSE CODE :- " + request.getResponseCode() + " --- ";

    Response<String> resultx = Rest.put(url).getAsString();

    result += resultx.getResponseData();
    resultTextArea.setText(result);
    Form hi = new Form("Test Connection Response", new BoxLayout(BoxLayout.Y_AXIS));

    Button mainFormButton = new Button("Back To Main Form");
    mainFormButton.addActionListener((e) -> mainForm());
    mainFormButton.setRippleEffect(true);
    hi.add(mainFormButton);

    hi.show();

    // request will be handled asynchronously
    NetworkManager.getInstance().addToQueue(request);
}
enter code here

enter image description here

sam
  • 63
  • 2
  • 7

1 Answers1

0

I'm assuming this works in the simulator and fails on the device?

There are multiple reasons this can happen but in this case it looks like a subnet IP address. You're trying to connect to an internal company URL from a device which is probably on the operator network. Try connecting to the URL via the browser and see if it's reachable by the device.

As a workaround you can connect to the company internal wifi and see if the server is reachable.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • hi . thanks for reply.. i do able to connect via browser too sir. and from also i am able to get response from the browser app which is installed in mobile too.. – sam Dec 13 '19 at 04:49
  • and you are also right i t works in simulator along with the older older google nexus 5 which have old version of android lolipop. But when i tired to run the same app in Samsung M30 and google pixel one i am having that issue . if there is any soluition then please let me know.. – sam Dec 13 '19 at 04:52
  • Maybe this is related to the problem? https://stackoverflow.com/questions/57121953/usescleartexttraffic-not-permitted – Shai Almog Dec 14 '19 at 02:55