简体   繁体   English

在Android中制作ConnectionRequest的最佳方式

[英]Best way to make a ConnectionRequest in Android

I coded this connection request using codenameone. 我用codenameone编写了这个连接请求。 I will like to know the best way to do the same thing on android. 我想知道在android上做同样事情的最好方法。 Any help please. 请帮忙。 I have searched around and not really getting anything solid. 我一直在寻找,并没有真正得到任何坚实的东西。 This is what I want to do. 这就是我想要做的。 Thanks. 谢谢。

public void doLogin(String username, String password) { public void doLogin(String username,String password){

    ConnectionRequest cr;
    cr = new ConnectionRequest() {
        Hashtable h;

        @Override
        protected void postResponse() {

        }

        @Override
        protected void readResponse(InputStream input) throws IOException {
            JSONParser parser = new JSONParser();
            h = parser.parse(new InputStreamReader(input));
            System.out.println("" + h);
            String username = (String) h.get("username");

            if (username != null) {
                user = username;
                showForm("Dashboard", null);

            }

        }

        @Override
        protected void handleErrorResponseCode(int code, String message) {
            if (code == 401) {
                Dialog.show("Failure", "Invalid Username or Password", "OK", null);
            }
        }

        @Override
        protected void handleException(Exception err) {
            Dialog.show("Failure", "Check Network", "OK", null);
        }

    };

    cr.addRequestHeader(AppConfig.REQUEST_HEADER, AppConfig.REQUEST_HEADER_VALUE);
    cr.setContentType(AppConfig.CONTENT_TYPE);
    cr.setUrl(AppConfig.BASE_URL + "authentication?username=" + username + "&password=" + password);
    cr.setPost(true);
    cr.setReadResponseForErrors(true);
    InfiniteProgress prog = new InfiniteProgress();
    Dialog dlg = prog.showInifiniteBlocking();
    cr.setDisposeOnCompletion(dlg);
    NetworkManager.getInstance().addToQueue(cr);

}

We support BluetoothLE which is where the industry is going. 我们支持BluetoothLE,这是行业发展的方向。 I would suggest avoiding that entirely for this use case and using a native interface to the OS's printing API's which are currently unmapped in Codename One. 我建议完全避免使用这个用例,并使用OS的打印API的本机接口,这些接口目前在Codename One中未映射。

For Android you can use the standard java.net.URL code and the org.json parsing API. 对于Android,您可以使用标准的java.net.URL代码和org.json解析API。

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

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