如何将Espresso的意图与DocumentsProvider结果一起使用

问题描述 投票:5回答:1

我的活动需要从文档提供者处请求新文档。

我想在意式浓缩咖啡测试中通过用uri指定活动结果来对此进行测试。但是,返回的uri没有授予正确的权限。当我尝试SecurityException: No persistable permission grants found for [user] and [uri]]时,至少我得到了takePersistableUriPermission

onActivityResult中我的活动的相关代码:

val takeFlags = data.getFlags() and (Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
contentResolver.takePersistableUriPermission(it, takeFlags)

浓缩咖啡测试的相关代码

val file = File(InstrumentationRegistry.getTargetContext().filesDir, "abc.txt2)
val uri = Uri.parse("file://" + file.absoluteFile)
Intents.intending(hasAction(Intent.ACTION_CREATE_DOCUMENT))
            .respondWith(Instrumentation.ActivityResult(RESULT_OK, Intent().setData(uri)))
 <click on button to request document>

如何使用已授予权限的uri来确定活动结果?

我的活动需要从文档提供者处请求新文档。我想在意式浓缩咖啡测试中通过指定uri的活动结果来对此进行测试。但是,返回的uri没有...

android android-espresso android-storage
1个回答
0
投票

使用

© www.soinside.com 2019 - 2024. All rights reserved.