简体   繁体   中英

Best way to make a ConnectionRequest in Android

I coded this connection request using codenameone. I will like to know the best way to do the same thing on 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) {

    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. 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.

For Android you can use the standard java.net.URL code and the org.json parsing API.

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