目前survey到有兩種方法(第二種簡單許多了 噗~)
//Method1: Use HTTP protocol POST to retrieve a image
HttpURLConnection con = (HttpURLConnection)(new URL(url)).openConnection();
con.setRequestMethod("GET");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
InputStream iis = new BufferedInputStream(con.getInputStream());
bitmap = BitmapFactory.decodeStream(iis);
//Method2
bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
使用時需要記得在AndroidManifest.xml 加入使用網路的權限
<uses-permission android:name="android.permission.INTERNET" />
沒有留言:
張貼留言