Quantcast
Channel: IT社区推荐资讯 - ITIndex.net
Viewing all articles
Browse latest Browse all 15843

android如何让webview里的资源访问本地缓存

$
0
0
继承并实现一个ContentProvider
package com.packagename.provider;
public class MyProvider extends ContentProvider {
     @Override
     public ParcelFileDescriptor openFile(Uri uri, String mode){
        URI fileURI = URI.create( "file://" + uri.getPath() );
        File file = new File( fileURI );

        ParcelFileDescriptor parcel = null;
        try {
            parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
        } catch (FileNotFoundException e) {
            Log.e( TAG, "Error finding: " + fileURI + "\n" + e.toString() );
        }

        return parcel;
     }
}

注册AndroidManifest.xml
<provider
        android:name=".provider.MyProvider"
        android:authorities="com.packagename" />

资源url
content://com.packagename/sdcard/Android/data/com.packagename/image.jpg

已有 0人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐




Viewing all articles
Browse latest Browse all 15843

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>