【问题标题】:AsyncTask Permission denied (missing INTERNET permission?)AsyncTask 权限被拒绝(缺少 INTERNET 权限?)
【发布时间】:2015-08-01 14:32:29
【问题描述】:

我正在尝试使用 AsyncTask 通过 Internet 提取图像并显示在 RecyclerViewer 上,但我收到以下错误消息,该消息是从我的 RecyclerViewAdapter 类的 doInBackground 中的异常中捕获的:

08-02 00:11:25.608: E/ImageDownload(5753): Download failed: Permission denied (missing INTERNET permission?)

在下面查看完整版的 AsyncTask 子类:

 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>

请帮忙!

【问题讨论】:

  • 似乎是服务器问题,您需要凭据才能下载图像

标签: android image url android-asynctask user-permissions


【解决方案1】:

将您的 &lt;uses-permission&gt; 元素移动为 &lt;manifest&gt; 的直接子代,在您的 &lt;application&gt; 元素上方。

【讨论】:

    【解决方案2】:

    将您的清单更新为:-

    <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>
    

    【讨论】:

      猜你喜欢
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 2014-06-29
      • 2011-02-26
      • 2011-08-09
      • 2015-08-30
      相关资源
      最近更新 更多