本文整理了Java中android.app.Instrumentation.getContext()
方法的一些代码示例,展示了Instrumentation.getContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.getContext()
方法的具体详情如下:
包路径:android.app.Instrumentation
类名称:Instrumentation
方法名:getContext
暂无
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public Context getContext() {
return base.getContext();
}
代码示例来源:origin: square/leakcanary
/** Can be overridden to customize the failure string message. */
protected @NonNull String buildLeakDetectedMessage(
@NonNull List<InstrumentationLeakResults.Result> detectedLeaks) {
StringBuilder failureMessage = new StringBuilder();
failureMessage.append(
"Test failed because memory leaks were detected, see leak traces below.\n");
failureMessage.append(SEPARATOR);
Context context = getInstrumentation().getContext();
for (InstrumentationLeakResults.Result detectedLeak : detectedLeaks) {
failureMessage.append(
LeakCanary.leakInfo(context, detectedLeak.heapDump, detectedLeak.analysisResult, true));
failureMessage.append(SEPARATOR);
}
return failureMessage.toString();
}
}
代码示例来源:origin: koral--/android-gif-drawable
@Before
public void setUp() {
final Context context = InstrumentationRegistry.getInstrumentation().getContext();
rootView = LayoutInflater.from(context).inflate(R.layout.attrributes, null, false);
}
代码示例来源:origin: card-io/card.io-Android-SDK
public CardScannerTester(CardIOActivity scanActivity, int currentFrameOrientation) {
super(scanActivity, currentFrameOrientation);
useCamera = false;
mScanAllowed = false;
mHandler = new Handler();
try {
Bitmap bitmap = BitmapFactory.decodeStream(getInstrumentation().getContext().getAssets()
.open("test_card_images/" + sCardAssetName));
mFrame = getNV21FormattedImage(bitmap.getWidth(), bitmap.getHeight(), bitmap);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: RobotiumTech/robotium
/**
* Creates and returns TextView objects based on WebElements
*
* @return an ArrayList with TextViews
*/
private ArrayList <TextView> createAndReturnTextViewsFromWebElements(boolean javaScriptWasExecuted){
ArrayList<TextView> webElementsAsTextViews = new ArrayList<TextView>();
if(javaScriptWasExecuted){
for(WebElement webElement : webElementCreator.getWebElementsFromWebViews()){
if(isWebElementSufficientlyShown(webElement)){
RobotiumTextView textView = new RobotiumTextView(inst.getContext(), webElement.getText(), webElement.getLocationX(), webElement.getLocationY());
webElementsAsTextViews.add(textView);
}
}
}
return webElementsAsTextViews;
}
代码示例来源:origin: googlemaps/android-maps-utils
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
代码示例来源:origin: googlemaps/android-maps-utils
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
代码示例来源:origin: googlemaps/android-maps-utils
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
代码示例来源:origin: koral--/android-gif-drawable
@Test
public void gifDrawableCreatedFromInputStream() throws Exception {
final AssetFileDescriptor assetFileDescriptor = InstrumentationRegistry.getInstrumentation()
.getContext().getResources().openRawResourceFd(R.raw.test);
final byte[] buffer = new byte[(int) assetFileDescriptor.getDeclaredLength()];
final FileInputStream inputStream = assetFileDescriptor.createInputStream();
final int bufferedByteCount = inputStream.read(buffer);
inputStream.close();
assetFileDescriptor.close();
assertThat(bufferedByteCount).isEqualTo(buffer.length);
final InputStream responseStream = new ByteArrayInputStream(buffer);
final GifDrawable gifDrawable = new GifDrawable(responseStream);
assertThat(gifDrawable.getError()).isEqualTo(GifError.NO_ERROR);
assertThat(gifDrawable.getIntrinsicWidth()).isEqualTo(278);
assertThat(gifDrawable.getIntrinsicHeight()).isEqualTo(183);
}
}
代码示例来源:origin: koral--/android-gif-drawable
@Test
public void allocationByteCountIsConsistent() throws Exception {
final Resources resources = InstrumentationRegistry.getInstrumentation().getContext().getResources();
final GifDrawable drawable = new GifDrawable(resources, R.raw.test);
final GifAnimationMetaData metaData = new GifAnimationMetaData(resources, R.raw.test);
assertThat(drawable.getFrameByteCount() + metaData.getAllocationByteCount()).isEqualTo(drawable.getAllocationByteCount());
assertThat(metaData.getDrawableAllocationByteCount(null, 1)).isEqualTo(drawable.getAllocationByteCount());
assertThat(metaData.getDrawableAllocationByteCount(drawable, 1)).isEqualTo(drawable.getAllocationByteCount());
}
}
代码示例来源:origin: FolioReader/FolioReader-Android
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getContext();
assertEquals("com.folioreader.android.sample", appContext.getPackageName());
}
}
代码示例来源:origin: westnordost/StreetComplete
@Before public void setUpList()
{
list = new ArrayList<>();
list.addAll(Arrays.asList(one, two, three, four, five));
questTypeOrderList = new QuestTypeOrderList(
getInstrumentation().getContext().getSharedPreferences("Test", Context.MODE_PRIVATE),
new QuestTypeRegistry(list));
questTypeOrderList.clear();
}
代码示例来源:origin: TomRoush/PdfBox-Android
@Before
public void setUp() throws Exception
{
testContext = InstrumentationRegistry.getInstrumentation().getContext();
PDFBoxResourceLoader.init(testContext);
TARGETTESTDIR = android.os.Environment.getExternalStorageDirectory() + "/Download/pdfbox-test-output/merge/";
new File(TARGETTESTDIR).mkdirs();
if (!new File(TARGETTESTDIR).exists())
{
throw new IOException("could not create output directory");
}
}
代码示例来源:origin: TomRoush/PdfBox-Android
@Before
public void setUp()
{
testContext = InstrumentationRegistry.getInstrumentation().getContext();
PDFBoxResourceLoader.init(testContext);
testResultsDir = new File(android.os.Environment.getExternalStorageDirectory() +
"/Download/pdfbox-test-output/graphics/");
testResultsDir.mkdirs();
}
代码示例来源:origin: TomRoush/PdfBox-Android
@Before
public void setUp()
{
testContext = InstrumentationRegistry.getInstrumentation().getContext();
PDFBoxResourceLoader.init(testContext);
testResultsDir = new File(android.os.Environment.getExternalStorageDirectory() +
"/Download/pdfbox-test-output/graphics/");
testResultsDir.mkdirs();
}
代码示例来源:origin: sphinx02/AppStarter
public void testCheckForUpdate() throws Exception {
KodiUpdater mKodiUpdater = new KodiUpdater(this.getInstrumentation().getContext());
mKodiUpdater.checkForUpdate(true);
assertNotNull("Latest version should not be null", mKodiUpdater.getLatestVersion());
}
}
代码示例来源:origin: labexp/osmtracker-android
@Override
protected void setUp() throws Exception {
trackId = MockData.mockTrack(getInstrumentation().getContext());
Intent i = new Intent();
i.putExtra(Schema.COL_TRACK_ID, trackId);
setActivityIntent(i);
}
代码示例来源:origin: TomRoush/PdfBox-Android
@Before
public void setUp() throws IOException
{
testContext = InstrumentationRegistry.getInstrumentation().getContext();
PDFBoxResourceLoader.init(testContext);
}
代码示例来源:origin: onehilltech/android-metadata
@Test(expected=NameNotFoundException.class)
public void testNameNotFoundException () throws Exception
{
ManifestMetadata metadata = ManifestMetadata.get (InstrumentationRegistry.getInstrumentation ().getContext ());
metadata.getValue ("foo", String.class);
}
代码示例来源:origin: plusonelabs/calendar-widget
public void testJsonToAndFrom() throws IOException, JSONException {
CalendarQueryResultsStorage inputs1 = provider.loadResults(getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.birthday);
JSONObject jsonOutput = inputs1.toJson(provider.getContext(), provider.getWidgetId());
CalendarQueryResultsStorage inputs2 =
CalendarQueryResultsStorage.fromJson(provider.getContext(), jsonOutput);
assertEquals(inputs1, inputs2);
}
}
内容来源于网络,如有侵权,请联系作者删除!