編輯:關於Android編程
package com.example.denglu; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { TextView textView; static String get; Handler handler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView=(TextView)findViewById(R.id.textview); handler=new Handler(){ public void handleMessage(android.os.Message msg) { textView.setText(get); }; }; new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub login(a, z); Message message=new Message(); Bundle dataBundle=new Bundle(); dataBundle.putString(a, b); message.setData(dataBundle); handler.sendMessage(message); } }).start(); } public static void login(String user,String pswd){ HttpClient httpClient=new DefaultHttpClient(); String uri=http://10.0.2.2:8080/sessionlogin/great; HttpPost httpPost=new HttpPost(uri); Listlist=new ArrayList (); list.add(new BasicNameValuePair(username,user)); list.add(new BasicNameValuePair(password,pswd)); try { UrlEncodedFormEntity entity=new UrlEncodedFormEntity(list, utf-8); httpPost.setEntity(entity); try { HttpResponse response=httpClient.execute(httpPost); if (response.getStatusLine().getStatusCode()==200) { InputStream inputStream=response.getEntity().getContent(); get=tostring(inputStream); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } static String tostring(InputStream inputStream){ ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(); byte[]buffer=new byte[1024]; int len=0; String a=null; try { while ((len=inputStream.read(buffer))!=-1) { byteArrayOutputStream.write(buffer, 0, len); } inputStream.close(); byteArrayOutputStream.close(); a=new String(buffer, utf-8); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return a; } }
前兩篇博客並分別講了獲取聯系人和通話記錄的知識,這篇主要介紹短信獲取知識,短信在通訊管理中應該說是一個難點,因為短信涉及到短息會話和短信詳情兩個部分,並且短信的數據量比較
前幾篇給大家講了有關繪圖的知識,這篇我們稍微停一下,來看下手機QQ中拖動刪除的效果是如何實現的;這篇涉及到的知識有:- saveLayer圖層相關知識- Path的貝賽爾
android app漢化與英化在res文件夾下面添加一個values-en-US文件夾,添加一個strings.xml文件,然後往裡面添加標簽對,系統語言換成英語就可以
復制代碼 代碼如下:package cn.aibow.android.layoutdemo1;import android.os.Bundle;import androi