android7.0 电子书,Android《7.0适配》

第一步

android:name="android.support.v4.content.FileProvider"

android:authorities="${applicationId}.android7.fileprovider"

android:exported="false"

android:grantUriPermissions="true">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/file_paths" />

第二部

name="root"

path="" />

name="files"

path="files" />

name="cache"

path="caches" />

name="external"

path="sdfiles" />

name="externalfiles"

path="sdfiles" />

name="externalcache"

path="sdfiles" />

第三部

public class FileProvider {

public static Uri getUriForFile(Context context, File file) {

Uri fileUri = null;

if (Build.VERSION.SDK_INT >= 24) {

fileUri = getUriForFile24(context, file);

} else {

fileUri = Uri.fromFile(file);

}

return fileUri;

}

public static Uri getUriForFile24(Context context, File file) {

Uri fileUri = android.support.v4.content.FileProvider.getUriForFile(context,

context.getPackageName() + ".android7.fileprovider",

file);

return fileUri;

}

}

第四部

File file = null;

Uri imageUri = null;

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

String filename = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.CHINA)

.format(new Date()) + ".png";

file = new File(filename);

Log.e("root-path", file.getAbsolutePath());

imageUri = FileProvider.getUriForFile(this, file);

Log.e("root-path", imageUri.toString());

Log.e("root-path", "---------------------------------------------------------");

file = new File(getFilesDir()+"/files/", filename);

Log.e("files-path", file.getAbsolutePath());

imageUri = FileProvider.getUriForFile(this, file);

Log.e("files-path", imageUri.toString());

Log.e("files-path", "---------------------------------------------------------");

file = new File(getCacheDir()+"/caches/", filename);

Log.e("cache-path", file.getAbsolutePath());

imageUri = FileProvider.getUriForFile(this, file);

Log.e("cache-path", imageUri.toString());

Log.e("cache-path", "---------------------------------------------------------");

file = new File(Environment.getExternalStorageDirectory()+"/sdfiles/", filename);

Log.e("external-path", file.getAbsolutePath());

imageUri = FileProvider.getUriForFile(this, file);

Log.e("external-path", imageUri.toString());

Log.e("external-path", "---------------------------------------------------------");

file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)+"/sdfiles/", filename);

Log.e("external-files-path", file.getAbsolutePath());

imageUri = FileProvider.getUriForFile(this, file);

Log.e("external-files-path", imageUri.toString());

Log.e("external-files-path", "---------------------------------------------------------");

file = new File(context.getExternalCacheDir()+"/sdfiles/", filename);

Log.e("external-cache-path", file.getAbsolutePath());

imageUri = FileProvider.getUriForFile(this, file);

Log.e("external-cache-path", imageUri.toString());

Log.e("external-cache-path", "---------------------------------------------------------");

第五步讲解对应关系

/com.bsoft.lwd.ferrysupport E/root-path: /20171106-165706.png

/com.bsoft.lwd.ferrysupport E/root-path: content://com.bsoft.lwd.ferrysupport.android7.fileprovider/root/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/root-path: ---------------------------------------------------------

/com.bsoft.lwd.ferrysupport E/files-path: /data/user/0/com.bsoft.lwd.ferrysupport/files/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/files-path: content://com.bsoft.lwd.ferrysupport.android7.fileprovider/files/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/files-path: ---------------------------------------------------------

/com.bsoft.lwd.ferrysupport E/cache-path: /data/user/0/com.bsoft.lwd.ferrysupport/cache/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/cache-path: content://com.bsoft.lwd.ferrysupport.android7.fileprovider/cache/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/cache-path: ---------------------------------------------------------

/com.bsoft.lwd.ferrysupport E/external-path: /storage/emulated/0/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/external-path: content://com.bsoft.lwd.ferrysupport.android7.fileprovider/external/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/external-path: ---------------------------------------------------------

/com.bsoft.lwd.ferrysupport E/external-files-path: /storage/emulated/0/Android/data/com.bsoft.lwd.ferrysupport/files/Pictures/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/external-files-path: content://com.bsoft.lwd.ferrysupport.android7.fileprovider/externalfiles/Pictures/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/external-files-path: ---------------------------------------------------------

/com.bsoft.lwd.ferrysupport E/external-cache-path: /storage/emulated/0/Android/data/com.bsoft.lwd.ferrysupport/cache/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/external-cache-path: content://com.bsoft.lwd.ferrysupport.android7.fileprovider/externalcache/20171106-165706.png

/com.bsoft.lwd.ferrysupport E/external-cache-path: ---------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值