[英]How do I access/read from/write to Documents folder in Internal Storage on Android devices?
[英]How do I access the internal storage from a test project?
我有一個使用測試數據的儀器測試。 我已將此測試數據作為資產文件包含在測試項目中,並且運行良好。
我想通過將測試數據文件推送到測試應用程序的內部存儲器來加速使用不同的測試數據重新運行測試,然后讓測試從內部存儲器讀取測試數據(如果存在)。
但是,我無法從測試應用程序訪問內部存儲。 我正在使用android.test.InstrumentationTestRunner
的子類,並且對getContext().getFilesDir()
所有調用getContext().getFilesDir()
返回null
。
測試應用程序無法訪問內部存儲嗎?
任何幫助是極大的贊賞。
如果您碰巧在測試中使用了Roboguice,請確保實現應用程序類的構造函數,如下所示:
public MyApplication(Instrumentation instrumentation) {
this();
attachBaseContext(instrumentation.getTargetContext());
//this does not work:
//attachBaseContext(instrumentation.getContext());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.