Android to realize Sina Weibo client's expressive function

Source: Internet
Author: User
Tags expression resource xml parser

Recently engaged in the Android Sina Weibo client, have some experience to share

To get the Android client expression function can use the following ideas

1. Home page to download the expression of Sina to a local folder species, expression of the name of the image to use Sina Weibo expression of the original name

For example, Sina's shy expression is shame.gif then you have to name the local shame.gif, the same name is mainly to be able to match the expression corresponding to the code.

2. Put the local expression into the Android resource file----drawable below

3. Visit Sina's facial expression interface (Sina returns the data type has JSON and XML two kinds, I use XML), put back the information, The information parsed by the XML parser is stored in a emotion.java bean, so that one by one corresponding resource emoticons can be found according to Emotion.java's code.

4. Realize a user to choose the expression interface, I use the GridView implementation

5. To achieve the click of the GridView each item, processing according to the item's index to find the corresponding expression code, and then the code used to convert the code to the corresponding expression picture, the final expression inserted edittext to send.

The following is a specific implementation process

1. Download the Sina expression picture to the local implementation as follows: (This can build a Java project to download)

public void Getfriendlist () throws Exception {Blogreleaseserviceimpl service = new Blogreleaseserviceimpl ();    
        list<emotions> list = Service.getemotion ();    
            for (emotions emotions:list) {String path = Emotions.geturl ();    
            String filename = path.substring (Path.lastindexof ("/") + 1,path.length ());    
            URL url = new URL (path);    
            HttpURLConnection conn = (httpurlconnection) url.openconnection ();    
            Conn.setrequestmethod ("get");    
            Conn.setreadtimeout (5 * 1000);    
                if (Conn.getresponsecode () = () {InputStream is = Conn.getinputstream ();    
                byte[] data = Readstream (IS);
                File File = new file ("F: \\sina_images\\" + filename);    
                FileOutputStream fs = new FileOutputStream (file);    
                Fs.write (data);    
            Fs.close ();    
                }else{SYSTEM.OUT.PRINTLN ("request Failed"); }} public byte[] Readstream (InputStream is) throws Exception {byt    
        Earrayoutputstream OS = new Bytearrayoutputstream ();    
        byte[] buffer = new byte[2048];    
        int len = 0;    
        while (len = is.read (buffer))!=-1) {os.write (Buffer,0,len);    
        } is.close ();    
    return Os.tobytearray (); }

2: Put the local expression into the Android resource file----drawable below (This is needless to say, directly select all files copied on the line)

3:

3.1 Access to Sina's expression interface, the returned information is as follows:

     <emotion>    
<phrase>[hee]</phrase>    
<type>face</type>    
<url>gif/ Tooth.gif    
</url>    
<is_hot>false</is_hot>    
<is_common>true</is_common>    
<order_number>0</order_number>    
<category></category>    
lt;/emotion>

Related Article

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.