我在嘗試從遠程URL創建位圖時遇到了一些問題。以下是摘錄:即使使用INTERNET權限,也無法從連接獲取圖像
Bitmap bm = null;
URL aURL = null;
try {
aURL = new URL("http://developer.android.com/assets/images/home/honeycomb-android.png");
} catch (MalformedURLException e) {
System.err.println(e);
}
if(aURL != null){
URLConnection conn = null;
BufferedInputStream bis = null;
InputStream is = null;
try {
conn = aURL.openConnection();
conn.connect();
is = conn.getInputStream();
bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
} catch (Exception e) {
System.err.println(e);
} finally {
if(bis != null){
try {
bis.close();
} catch (IOException e) {}
}
if(is != null){
try {
is.close();
} catch (IOException e) {}
}
conn = null;
}
}
我在conn.connect()
行中收到異常。它說 java.net.SocketException: Permission denied
。
我已經加入清單中的權限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="mypackage.namehere">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
</application>
</manifest>
我既可以從我的電腦瀏覽器和模擬器瀏覽器加載圖像。沒有防火牆阻止我的互聯網連接。 嘗試了幾個網址,但沒有任何工作。
我是否正確打開連接?我應該使用HttpConnection嗎?
您是否對使用webview的使用感到滿意? –
黑暗中射擊:你可以張貼你的清單嗎? – Otra
@你在這裏,在上面編輯。 –