I want to put data in xml file of androidTest/res/values/string.xml folder. I have created the file say test.xml with below contents.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="test">hello</string>
</resources>
When i am trying to access the field test via R.string.test. It is not accessible and says "cannot resolve symbol test". Can someone please advice me here.
androidx.test.platform.app.InstrumentationRegistry
is deprecated use androidx.test.core.app.ApplicationProvider
val targetContext = ApplicationProvider.getApplicationContext<Context>()
val test: String = targetContext.resources.getString(R.string.test)
This is how you do it:
import com.my.example.test.R;
Resources resources = InstrumentationRegistry.getContext().getResources();
String terms = resources.getString(R.string.test);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With