简体   繁体   中英

Network error on some devices after build

I installed the app after build on different devices (Android) the app opens up fine but when sending network request only one of the device is able to send successfully the others remain unresponsive. Am using the Rest.post() to send that particular request. Using codename one 6.0 but updated it this morning so I will be using the recent version. Note: the situation happened before the update. i added a bunch of things while trying to locate the problem. Here is the code:

//...Login button ActionListner
gui_Button_login.addActionListener((ae)->{
        gui_Infinite_Progress.setVisible(true);
        gui_Infinite_Progress.setEnabled(true);
        gui_Button_login.setEnabled(false);
        gui_Text_Field_username.setEnabled(false);
        gui_Text_Field_Password.setEnabled(false);
        if(doLogin()){
            Handle.UserFeed = new UserFeedForm();
            Handle.UserFeed.show();
        }else{
            gui_Button_login.setEnabled(true);
            gui_Text_Field_username.setEnabled(true);
            gui_Text_Field_Password.setEnabled(true);
            gui_Infinite_Progress.setVisible(false);
            gui_Infinite_Progress.setEnabled(false);
        }
    });
//...Do login function
private boolean doLogin(){
    String usr_username = gui_Text_Field_username.getText();
    String usr_password = gui_Text_Field_Password.getText();
    Map<String, Object> signInData = new HashMap<>();
    signInData.put("usr_username", usr_username);
    signInData.put("usr_password", usr_password);
    String signInDataJSON = JSONParser.mapToJson(signInData);

    gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nData:\n"+ signInDataJSON);
    gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nSending...");
    Response<Map> response = Rest.post(Data.API_SIGNIN_URL)
            .jsonContent()
            .body(signInDataJSON)
            .acceptJson()
            .onErrorCodeJSON(err->{
                ToastBar.showErrorMessage(err.getResponseErrorMessage(), Data.MESSAGE_ERROR_TIMEOUT);
                //gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nError:\n"+ err.getResponseErrorMessage());

            }).getAsJsonMap();

    Map<String, Object> responseData = response.getResponseData();
    if(response.getResponseCode() == 0){
        ToastBar.showErrorMessage("Please check your internet!", Data.MESSAGE_ERROR_TIMEOUT);

    }
    gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nResponse Code:\n"+ response.getResponseCode());
    gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nResponse Error Msg:\n"+ response.getResponseErrorMessage());

    if(responseData == null){
        return false;
    }

    if(((String)responseData.get("status")).equalsIgnoreCase("error")){
        ToastBar.showErrorMessage((String)responseData.get("msg"), Data.MESSAGE_ERROR_TIMEOUT);
        return false;
    }

    if(((String)responseData.get("status")).equalsIgnoreCase("success")){
        ToastBar.showMessage((String)responseData.get("msg"), FontImage.MATERIAL_CHECK_CIRCLE, Data.MESSAGE_SUCCESS_TIMEOUT);
        Handle.LoggedInUserData = (Map<String, Object>) responseData.get("data");
        Handle.Authority = (String)Handle.LoggedInUserData.get("jwt");
        return true;
    }
    return false;
}
//...

Data.API_SIGNIN_URL is a string containing address accessible via internet eg http://94.543.23.4/

I'm guessing you are trying to connect via an IP to a specific machine and it isn't working. This machine is probably visible only within your internal network and the other devices aren't connected to the internal network or choose a route via cell towers.

well i added the build hint android.xpermissions and set the value to android.permission.INTERNET\\=true,android.permission.WRITE_EXTERNAL_STORAGE\\=true,android.permission.READ_EXTERNAL_STORAGE\\=true .

Its working but seems redundant to me since according to codenameone docs Internet permission is inserted by default. i added the storage just to avert possible similar situation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM