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>