Get started with Android from Java proficiency

Source: Internet
Author: User

Just came out of school, alas, from Java to Android.

The teacher told us that Android is not important, the result, all the Android class is not playing mobile phone is talking, not serious listening and not serious, homework is not serious, now think good regret ah, so that they will only a button and TextView,

Recently in the company, I first put the previous network programming, and then slightly learn a bit okhttp, because I now only need to know how to use it, after all, the previous Android Foundation is not very good, first learn to use, later have time in slowly understand his method of realization, And httpclient Some of the methods, now the time is estimated too late, first learn to use again. Let me tell you about some of my recent experiences.

The first okhttp POST request (carries an administrator user name (userName) for admin888 request data in the request body, everyone expands according to individual needs):

Request Request = Buildmultipartformrequest (        newnewnullNew  Formencodingbuilder ();   Builder.add ("UserName", "admin888",new  request.builder ()                   . URL (URL)                . Post ( Builder.build ())                . Build (); Mokhttpclient.newcall (Request). Enqueue (new Callback () {});

The second okhttp file is uploaded (a key-value pair is passed to the server userName:admin888 and an ebook txt with a file name of 1):

File File =NewFile (Environment.getexternalstoragedirectory (), "1.txt"); Requestbody Filebody= Requestbody.create (Mediatype.parse ("Application/octet-stream"), file); Requestbody Requestbody=NewMultipartbuilder (). Type (Multipartbuilder.form). Addpart (Headers.of ("Content-disposition",               "Form-data; Name=\ "Username\" "), Requestbody.create (NULL, "admin888"). Addpart (Headers.of ("Content-disposition",          "Form-data;          Name=\ "Mfile\"; Filename=\ "1.txt\" "), Filebody). Build (); Request Request=Newrequest.builder (). URL ("File Upload Address"). Post (Requestbody). build (); Call Call=Mokhttpclient.newcall (request); Call.enqueue (NewCallback () {//Write a method here});

Get started with Android from Java proficiency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.