Android ContentProvider 提供 Assets 目录下的图片或文件
Android 大约 1294 字提供 Assets 目录下文件
@Nullable
@Override
public AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
AssetFileDescriptor afd = null;
try {
afd = mContext.getAssets().openFd("pic/" + imageName);
} catch (IOException e) {
e.printStackTrace();
}
return afd;
}
提供指定目录下文件
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
try {
File logoFile = LoadLogo.getLogoFile(getContext(), number);
if (logoFile != null && logoFile.exists()) {
return ParcelFileDescriptor.open(logoFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
} catch (Exception e) {
e.printStackTrace();
}
throw new FileNotFoundException(uri.getPath());
}
public static File getLogoFile(Context ctx, String number) {
StringBuilder sbNumLogo = new StringBuilder(ctx.getFilesDir().getAbsolutePath());
sbNumLogo.append(File.separator);
sbNumLogo.append(LOGO_PATH);
sbNumLogo.append(File.separator);
sbNumLogo.append(PhoneNumberFormat.getFormattedNumber(number));
File numLogo = new File(sbNumLogo.toString());
if (numLogo.exists()) {
return numLogo;
}
return null;
}
阅读 1420 · 发布于 2019-04-12
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Oracle 数据库连接异常 ORA-28000: the account is locked阅读 2385
-
算法:无重复字符的最长子串阅读 522
-
Docker 部署 Prometheus阅读 263
-
OpenResty 中使用 lua-resty-http 完成 HTTP 请求阅读 9058
-
Golang 加密算法之 md5阅读 690
-
Android 自动提示控件 AutoCompleteTextView阅读 1313
-
软考-系统架构设计师:政府信息化与电子政务阅读 1252
-
GoJS 给右键菜单中的按钮添加内边距阅读 392
-
Linux 之 CentOS yum 安装 PHP7.2阅读 1779
-
前端 Chrome 反《反调试》阅读 6573