GVKun编程网logo

使用Universal-Image-Downloader下载图像时出现SecurityException(universal image loader)

12

在这篇文章中,我们将为您详细介绍使用Universal-Image-Downloader下载图像时出现SecurityException的内容,并且讨论关于universalimageloader的相

在这篇文章中,我们将为您详细介绍使用Universal-Image-Downloader下载图像时出现SecurityException的内容,并且讨论关于universal image loader的相关问题。此外,我们还会涉及一些关于.net – 在SQL Server上执行用户定义函数时出现System.Security.HostProtectionException、android – DownloadManager.Request.setNotificationVisibility失败,出现SecurityException:可见性值无效:2、android – ListView加载图像时非常慢(使用Universal Image Loader)、android – Universal Image Loader在每次滚动后重新加载图像的知识,以帮助您更全面地了解这个主题。

本文目录一览:

使用Universal-Image-Downloader下载图像时出现SecurityException(universal image loader)

使用Universal-Image-Downloader下载图像时出现SecurityException(universal image loader)

在我的应用程序上,我使用通用的图像下载器BaseImageDownloader类同步加载画廊的内容。对于来自Imageloader.getInstance()。loadImage异步函数的相同内容,它不会给出任何安全异常并按原样加载图像,但是当我尝试使用BaseImageDownloader同步下载它(而且Imageloader.getInstance()。loadImage()相同),我得到了此安全异常

09-02 18:49:43.971: W/System.err(4244): java.lang.SecurityException: Permission Denial: reading com.android.gallery3d.provider.GalleryProvider uri content://com.google.android.gallery3d.provider/picasa/item/5879964074642783474 from pid=4244, uid=10064 requires com.google.android.gallery3d.permission.GALLERY_PROVIDER, or grantUriPermission()09-02 18:49:43.971: W/System.err(4244):     at android.os.Parcel.readException(Parcel.java:1425)09-02 18:49:43.971: W/System.err(4244):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)09-02 18:49:43.971: W/System.err(4244):     at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)09-02 18:49:43.971: W/System.err(4244):     at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:617)09-02 18:49:43.971: W/System.err(4244):     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:717)09-02 18:49:44.011: W/System.err(4244):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)09-02 18:49:44.011: W/System.err(4244):     at android.content.ContentResolver.openInputStream(ContentResolver.java:449)09-02 18:49:44.011: W/System.err(4244):     at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromContent(BaseImageDownloader.java:156)09-02 18:49:44.011: W/System.err(4244):     at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:88)09-02 18:49:44.011: W/System.err(4244):     at com.uploader.data.UploadImageData.decodeSampledBitmapFromStream(UploadImageData.java:80)

我也搜索了代码,但您对配置或其他地方没有任何许可,这是什么原因?

public Bitmap decodeSampledBitmapFromStream(String path, int reqWidth, int reqHeight) throws IOException {        BaseImageDownloader downloader = new BaseImageDownloader(getApplicationContext());        InputStream stream = downloader.getStream(path, null);        final BitmapFactory.Options options = new BitmapFactory.Options();        options.inJustDecodeBounds = true;        BitmapFactory.decodeStream(stream, new Rect(-1,-1,-1,-1), options);        stream.close();        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);        options.inJustDecodeBounds = false;        stream = downloader.getStream(path, null);        Bitmap bitmap = BitmapFactory.decodeStream(stream, new Rect(-1,-1,-1,-1), options);        stream.close();        return bitmap;    }

答案1

小编典典

我向mainfest添加了权限,并且它起作用了。但是我不知道没有它,UIL是如何制造的?

<uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/>

.net – 在SQL Server上执行用户定义函数时出现System.Security.HostProtectionException

.net – 在SQL Server上执行用户定义函数时出现System.Security.HostProtectionException

我编写了一个用户定义函数,它获取UtcTimeStamp和 windowstimezoneid作为参数,并返回TimeZone的TimeStamp.

但如果我想在一个简单的选择中执行它我得到以下错误:

A .NET Framework error occurred during execution of user-defined routine or aggregate "ToLocalTime": 
System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.

The protected resources (only available with full trust) were: All
The demanded resources were: MayLeakOnAbort

System.Security.HostProtectionException: 
   bei TimeFunctions.ToLocalTime(DateTime UtcTimestamp,String WindowsTimeZoneId)

我执行select as sa.我将clr设置为1.我使用sql Server 2008 R2(10.50.1600).

有谁知道我必须设置什么才能使这个工作或我可能做错了什么?

解决方法

CLR程序集有 trust levels.

这个需要UNSAFE权限,因为使用“MayLeakOnAbort”所需的权利

将CLR更改为更安全的内容,或者使用UNSAFE权限重新添加程序集. “UNSAFE”这个词当然是……

android – DownloadManager.Request.setNotificationVisibility失败,出现SecurityException:可见性值无效:2

android – DownloadManager.Request.setNotificationVisibility失败,出现SecurityException:可见性值无效:2

我正在尝试在我的服务类中使用DownloadManager:

    DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    //imageUri is a valid Uri
    Request downloadRequest= new Request(imageUri); 
    //without this line, it works
    downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
    //subpath is valid
    downloadRequest.setDestinationInExternalFilesDir(this, null, subPath);
    downloadManager.enqueue(downloadRequest);

如果没有setNotificationVisibility,此代码运行良好.但它显示了一个我不想要的通知,因为我使用此代码在ListView中加载延迟图像.

据我所知,这个通知可以隐藏起来

downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);

但在这种情况下,我的应用程序崩溃:

02-19 02:24:24.055: E/AndroidRuntime(2572):
java.lang.SecurityException: Invalid value for visibility: 2 02-19
02:24:24.055: E/AndroidRuntime(2572): at
android.os.Parcel.readException(Parcel.java:1327) 02-19 02:24:24.055:
E/AndroidRuntime(2572): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
02-19 02:24:24.055: E/AndroidRuntime(2572): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
02-19 02:24:24.055: E/AndroidRuntime(2572): at
android.content.ContentProviderProxy.insert(ContentProviderNative.java:415)
02-19 02:24:24.055: E/AndroidRuntime(2572): at
android.content.ContentResolver.insert(ContentResolver.java:730) 02-19
02:24:24.055: E/AndroidRuntime(2572): at
android.app.DownloadManager.enqueue(DownloadManager.java:885) 02-19
02:24:24.055: E/AndroidRuntime(2572): at
MyService.getimage(MyService.java:112)

setNotificationVisibility有什么问题?我怎么能收到通知?

解决方法:

根据文档,您需要在清单中具有以下权限:

<uses-permission
        android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

android – ListView加载图像时非常慢(使用Universal Image Loader)

android – ListView加载图像时非常慢(使用Universal Image Loader)

我的listView只用文本运行非常流畅 – 但是一旦我尝试加载缩略图(甚至从缓存中),它就会运行SOO波动.

我正在使用Universal Image Loader script

我的ArticleEntryAdapter中的代码在公共View getView(…)方法中:

/**
     * PHOTOS
     */
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this.mContext)
        .enableLogging()
        .memoryCacheSize(41943040)
        .discCacheSize(104857600)
        .threadPoolSize(10)
        .build();

    displayImageOptions imgdisplayOptions = new displayImageOptions.Builder()
        //.showStubImage(R.drawable.stub_image)
        .cacheInMemory() 
        .cacheOndisc() 
        //.imageScaleType(ImageScaleType.EXACT) 
        .build();

    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);

    //loads image (or hides image area)
    imageLoader.displayImage("", viewHolder.thumbView); //clears prevIoUs one
    if(article.photopath != null && article.photopath.length() != 0)
    {
        imageLoader.displayImage(
            "http://img.mysite.com/processes/resize_android.PHP?image=" + article.photopath + "&size=150&quality=80",
            viewHolder.thumbView,
            imgdisplayOptions
            );
        viewHolder.thumbView.setVisibility(View.VISIBLE);
    }
    else
    {
        viewHolder.thumbView.setVisibility(View.GONE); //hide image
        viewHolder.thumbView.invalidate(); //should call after changing to GONE
    }

Logcat显示它正在从缓存中加载图像(我认为):

ImageLoader    Load image from memory cache [http://img.mysite.com/processes/...

我正在我的三星galaxy Nexus上测试它并运行Android 4.0.4(虽然我的minSdkVersion =“8”)

解决方法:

将您的getView方法之外的ImageLoaderConfiguration配置,displayImageOptions imgdisplayOptions,ImageLoader imageLoader的瞬间作为Adapter类的私有字段/成员.你应该只创建一次这些东西,而不是每次调用getView.

编辑:没有看到你的整个Adapter类,这里是我正在说的东西.我希望它接近你拥有的东西,你可以使它成功. Lemme知道任何一种方式.

public class MyAdapterClass extends BaseAdapter {
    /**
     * PHOTOS
     */
    static ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this.mContext)
        .enableLogging()
        .memoryCacheSize(41943040)
        .discCacheSize(104857600)
        .threadPoolSize(10)
        .build();

    static displayImageOptions imgdisplayOptions = new displayImageOptions.Builder()
        //.showStubImage(R.drawable.stub_image)
        .cacheInMemory() 
        .cacheOndisc() 
        //.imageScaleType(ImageScaleType.EXACT) 
        .build();

    static ImageLoader imageLoader = ImageLoader.getInstance();
    /**
     * 
     */
    public MyAdapterClass() {
        // Todo Auto-generated constructor stub
        imageLoader.init(config);           
    }

    /* (non-Javadoc)
     * @see android.widget.Adapter#getCount()
     */
    public int getCount() {
        // Todo Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see android.widget.Adapter#getItem(int)
     */
    public Object getItem(int position) {
        // Todo Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see android.widget.Adapter#getItemId(int)
     */
    public long getItemId(int position) {
        // Todo Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    public View getView(int position, View convertView, ViewGroup parent) {
        //loads image (or hides image area)
        imageLoader.displayImage("", viewHolder.thumbView); //clears prevIoUs one
        if(article.photopath != null && article.photopath.length() != 0)
        {
            imageLoader.displayImage(
                "http://img.mysite.com/processes/resize_android.PHP?image=" + article.photopath + "&size=150&quality=80",
                viewHolder.thumbView,
                imgdisplayOptions
                );
            viewHolder.thumbView.setVisibility(View.VISIBLE);
        }
        else
        {
            viewHolder.thumbView.setVisibility(View.GONE); //hide image
            viewHolder.thumbView.invalidate(); //should call after changing to GONE
        }
    }

}

android – Universal Image Loader在每次滚动后重新加载图像

android – Universal Image Loader在每次滚动后重新加载图像

根据标题,如何在ListView中的每次滚动后停止UIL重新加载图像?

以下是我实现Image Loader的方法:

public class LatestAdapter extends BaseAdapter {

    ...

    // UIL
    private ImageLoaderConfiguration config;
    private File cacheDir;
    private displayImageOptions options;
    private ImageLoader imageLoader = ImageLoader.getInstance();

    public LatestAdapter(Context context,ArrayList<ItemListModel> items) {
        this.arrItemList = items;
        this.context = context;

        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"JunkFolder");
        else
            cacheDir=context.getCacheDir();
        if(!cacheDir.exists())
            cacheDir.mkdirs();

        options = new displayImageOptions.Builder()
                .showImageOnLoading(R.drawable.placeholder)
                .showImageOnFail(R.drawable.error)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
                .build();

        config = new ImageLoaderConfiguration.Builder(context)
                .memoryCache(new WeakMemoryCache())
                .denyCacheImageMultipleSizesInMemory()
                .discCache(new UnlimiteddiscCache(cacheDir))
                .threadPoolSize(5)
                .defaultdisplayImageOptions(options)
                .build();


        imageLoader.init(config);
    }

    ...

    @Override
    public View getView(int i,View view,ViewGroup viewGroup) {

        ...

        imageLoader.displayImage(nm.getThumbnail().getimage100(),vh.tvThumbnail,options,new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s,View view) {
            }

            @Override
            public void onLoadingFailed(String s,FailReason failReason) {
            }

            @Override
            public void onLoadingComplete(String s,Bitmap bitmap) {
            }

            @Override
            public void onLoadingCancelled(String s,View view) {
            }
        });
    }
}

每次我滚动ListView(向上或向下),它都不会保存以前加载的图像,而是重新加载ImageView.如何“保存”图像,使其不会在每个卷轴上闪烁?

解决方法

你将无法保存ime.列表适配器创建显示的项目以及上方和下方的一些项目.所有其他项目都将被销毁,然后在需要时重新创建.这就是convertView的目的.

在ImageLoader库中,即使您有缓存,在创建项目时,lib会查找某些缓存的图像然后显示它,或者在网络上下载它.

现在,第一次创建映像时,从网络获取映像并缓存它需要一些时间.

其他时候创建它,需要时间,很少的时间来查看缓存并显示它.但它不是即时显示……

今天的关于使用Universal-Image-Downloader下载图像时出现SecurityExceptionuniversal image loader的分享已经结束,谢谢您的关注,如果想了解更多关于.net – 在SQL Server上执行用户定义函数时出现System.Security.HostProtectionException、android – DownloadManager.Request.setNotificationVisibility失败,出现SecurityException:可见性值无效:2、android – ListView加载图像时非常慢(使用Universal Image Loader)、android – Universal Image Loader在每次滚动后重新加载图像的相关知识,请在本站进行查询。

本文标签: