栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

应用程式中的Android Image Viewer

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

应用程式中的Android Image Viewer

一种方法是实现上下文提供程序,以使其他应用程序可以访问您的数据。

创建一个包含以下内容的新类:

public class FileContentProvider extends ContentProvider {   private static final String URI_PREFIX = "content://uk.co.ashtonbrsc.examplefilecontentprovider";   public static String constructUri(String url) {       Uri uri = Uri.parse(url);       return uri.isAbsolute() ? url : URI_PREFIX + url;   }   @Override   public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {       File file = new File(uri.getPath());       ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);       return parcel;   }   @Override   public boolean onCreate() {       return true;   }   @Override   public int delete(Uri uri, String s, String[] as) {       throw new UnsupportedOperationException("Not supported by this provider");   }   @Override   public String getType(Uri uri) {   throw new UnsupportedOperationException("Not supported by this provider");   }   @Override   public Uri insert(Uri uri, ContentValues contentvalues) {       throw new UnsupportedOperationException("Not supported by this provider");   }   @Override   public Cursor query(Uri uri, String[] as, String s, String[] as1, String s1) {       throw new UnsupportedOperationException("Not supported by this provider");   }   @Override   public int update(Uri uri, ContentValues contentvalues, String s, String[] as) {       throw new UnsupportedOperationException("Not supported by this provider");   }}

将内容提供者添加到您的AndroidManifest.xml中:

<provider android:name=".FileContentProvider" android:authorities="uk.co.ashtonbrsc.examplefilecontentprovider" />

然后,您应该可以

"content://uk.co.ashtonbrsc.examplefilecontentprovider/" + the fullpath to the image
在ACTION_VIEW意向中使用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506239.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号