继承并实现一个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推荐