0

I am retrieving a file from my android test project by using the assets folder. The file can be loaded as an InputStream, but i need the url location of the file, is there a way to retriev the url without saving the file again and use the new file url, because the file is already there.

This is my current code to load the inputstream

    Context testContext = getInstrumentation().getContext();
    InputStream input = testContext.getAssets().open("attachment.png");

Is there a way the retrieve an url of this file instead of the inputstream?

Al Phaba
  • 6,545
  • 12
  • 51
  • 83

1 Answers1

1

You can create a URL using the following,

file:///android_asset/yourPath

where yourPath is the relative path of your asset file.

Please do note the 3 slashes (///). They are important. :)

Similar post here.

Community
  • 1
  • 1
Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
  • Ok, I can retrieve the url of the file in my testcase. But during the testcase this url will be used on the device to load a file, but this will not be found with the given url. I guess because this file is only available in my testproject and not in the application project. What is the correct procedure to using test files in an test project, so that they can be used for the tests? – Al Phaba Apr 28 '14 at 15:34