AsyncTask 权限被拒绝(缺少 INTERNET 权限?)
AsyncTask Permission denied (missing INTERNET permission?)
我正在尝试使用 AsyncTask 通过 Internet 提取图像并显示在 RecyclerViewer 上,但我收到以下错误消息,该消息是从我的 RecyclerViewAdapter class 的 doInBackground 异常中捕获的:
08-02 00:11:25.608: E/ImageDownload(5753): Download failed: Permission denied (missing INTERNET permission?)
请参阅下面的 AsyncTask 子 class 的完整版本:
class GetImageFromNet extends AsyncTask<String, Void, Bitmap> {
private RVAdapter.PersonViewHolder personViewHolder;
private String url = "http://ia.media-imdb.com/images/M/MV5BNDMyODU3ODk3Ml5BMl5BanBnXkFtZTgwNDc1ODkwNjE@._V1_SX300.jpg";
public GetImageFromNet(RVAdapter.PersonViewHolder personViewHolder){
this.personViewHolder = personViewHolder;
}
protected Bitmap doInBackground(String... params) {
try {
InputStream in = new java.net.URL(url).openStream();
Bitmap bitmap = BitmapFactory.decodeStream(in);
return bitmap;
//NOTE: it is not thread-safe to set the ImageView from inside this method. It must be done in onPostExecute()
} catch (Exception e) {
Log.e("ImageDownload", "Download failed: " + e.getMessage());
}
return null;
}
protected void onPostExecute(Bitmap bitmap) {
if (isCancelled()) {
bitmap = null;
}
personViewHolder.personPhoto.setImageBitmap(bitmap);
}
我不知道为什么会出现上述错误,因为我已经在 AndroidManifest.xml:
中添加了以下权限访问
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
请帮忙!
将 <uses-permission>
元素移至 <manifest>
的直接子元素,置于 <application>
元素上方。
将清单更新为:-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我正在尝试使用 AsyncTask 通过 Internet 提取图像并显示在 RecyclerViewer 上,但我收到以下错误消息,该消息是从我的 RecyclerViewAdapter class 的 doInBackground 异常中捕获的:
08-02 00:11:25.608: E/ImageDownload(5753): Download failed: Permission denied (missing INTERNET permission?)
请参阅下面的 AsyncTask 子 class 的完整版本:
class GetImageFromNet extends AsyncTask<String, Void, Bitmap> {
private RVAdapter.PersonViewHolder personViewHolder;
private String url = "http://ia.media-imdb.com/images/M/MV5BNDMyODU3ODk3Ml5BMl5BanBnXkFtZTgwNDc1ODkwNjE@._V1_SX300.jpg";
public GetImageFromNet(RVAdapter.PersonViewHolder personViewHolder){
this.personViewHolder = personViewHolder;
}
protected Bitmap doInBackground(String... params) {
try {
InputStream in = new java.net.URL(url).openStream();
Bitmap bitmap = BitmapFactory.decodeStream(in);
return bitmap;
//NOTE: it is not thread-safe to set the ImageView from inside this method. It must be done in onPostExecute()
} catch (Exception e) {
Log.e("ImageDownload", "Download failed: " + e.getMessage());
}
return null;
}
protected void onPostExecute(Bitmap bitmap) {
if (isCancelled()) {
bitmap = null;
}
personViewHolder.personPhoto.setImageBitmap(bitmap);
}
我不知道为什么会出现上述错误,因为我已经在 AndroidManifest.xml:
中添加了以下权限访问<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
请帮忙!
将 <uses-permission>
元素移至 <manifest>
的直接子元素,置于 <application>
元素上方。
将清单更新为:-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>