編輯:關於Android編程
package com.example.utils; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class StreamTool { public static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream();// 輸出流,寫到內存 byte[] buffer = new byte[1024];// 1K緩沖區容量 int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len);// 從數組buffer中讀取從0到len的數據 } inStream.close(); return outStream.toByteArray(); } }
package com.example.image; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import com.example.utils.StreamTool; public class HtmlService { public static String getHtml(String path) throws Throwable { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5 * 1000); InputStream inStream = conn.getInputStream();// 通過輸入流獲取html數據 byte[] data = StreamTool.readInputStream(inStream);// 得到的html的二進制數據 String html= new String(data,"utf-8"); return (html); } }
package com.example.image; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private static final String TAG="htmlcodeview"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image); TextView textView=(TextView)this.findViewById(R.id.textView); try { textView.setText(HtmlService.getHtml("www.baidu.con")); } catch (Throwable e) { Log.e(TAG, e.toString()); Toast.makeText(MainActivity.this, "error", 1) .show(); } } } // //
簡介作為Android開發者,我們經常需要自定義控件,比如下面我們說的實現圖片的多點觸控和伸縮釋放,這也是由於用戶已經有這樣的常識了,那就是看見有圖片的地方就可以點擊查看
Android中相機和相冊使用分析 歡迎轉載,但請尊重原創(文章來自不易,轉載請標明轉載出處,謝謝) 在手機應用程序中,使用自帶的相機拍照以及相冊選擇喜歡的圖片是
效果和代碼都非常直觀:實例1:TimePicker<RelativeLayout xmlns:android=http://schemas.android.com/
Activity是什麼?我們都知道android中有四大組件(Activity 活動,Service 服務,Content Provider 內容提供者,Broadcas