android如何让webview里的资源访问本地缓存
继承并实现一个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