正在开发一个图库应用,用户可以删除图片,但删除功能无法在OnePlus3中使用。
五天前我在多台设备上进行测试Android FileProvider delete file前问了一个类似的问题,然后才发现真实的场景。
我测试的设备:
Emulator-Pixel XL API25 - Working
Emulator-Pixel XL API24 - Working
Emulator-Nexus 5X API25 - Working
Emulator-Nexus 5 API23 - Working
Device-MotoXPlay API23 - Working
Device-MotoXForce API24 - Working
Device-SamsungS7Edge API24 - Working
Device-OnePlusX API23 - Working
Device-OnePlus3 API25 - Not Working
清单
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.zo.tns1.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileaccess_paths"/>
路径
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<internal-path
name="internal"
path="." />
</paths>
代码
Uri deleteFileUri = FileProvider.getUriForFile(context, "com.zo.tns1.fileprovider", new File(filePath));
int fileDeleted = context.getContentResolver().delete(deleteFileUri, null, null);
Log.d(TAG, "File delete -> " + fileDeleted);
URI输出
/storage/emulated/0/DCIM/Camera/IMG_20170421_112804_1.jpg
context.getContentResolver().delete()
在OnePlus3中返回 0 ,找不到真正的原因。这是因为氧气OS吗?
感谢任何帮助,谢谢。