简体   繁体   English

构建后某些设备上的网络错误

[英]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. 我在不同设备(Android)上构建后安装了该应用程序,但该应用程序可以正常打开,但是在发送网络请求时,只有其中一个设备能够成功发送,其他设备仍然无法响应。 Am using the Rest.post() to send that particular request. 我正在使用Rest.post()发送该特定请求。 Using codename one 6.0 but updated it this morning so I will be using the recent version. 使用代号为6.0,但今天上午进行了更新,因此我将使用最新版本。 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/ Data.API_SIGNIN_URL是包含可通过Internet访问的地址的字符串,例如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. 我猜您正在尝试通过IP连接到特定计算机,但它不起作用。 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 . 好吧,我添加了构建提示android.xpermissions并将其值设置为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. 它的工作,但对我来说似乎多余,因为根据codenameone docs默认情况下插入Internet权限。 i added the storage just to avert possible similar situation 我添加存储只是为了避免可能的类似情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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