Java Code Examples for android.app.Instrumentation#getContext()
The following examples show how to use
android.app.Instrumentation#getContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileCompatTest.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
/** * Prefer internal over external storage, because external tends to be FAT filesystems, * which don't support symlinks (which we test using this method). */ public static File getWriteableDir(Instrumentation instrumentation) { Context context = instrumentation.getContext(); Context targetContext = instrumentation.getTargetContext(); File[] dirsToTry = new File[]{ context.getCacheDir(), context.getFilesDir(), targetContext.getCacheDir(), targetContext.getFilesDir(), context.getExternalCacheDir(), context.getExternalFilesDir(null), targetContext.getExternalCacheDir(), targetContext.getExternalFilesDir(null), Environment.getExternalStorageDirectory(), }; return getWriteableDir(dirsToTry); }
Example 2
Source File: UiDevice.java From za-Farmer with MIT License | 5 votes |
/** Private constructor. Clients should use {@link UiDevice#getInstance(Instrumentation)}. */ private UiDevice(Instrumentation instrumentation) { mInstrumentation = instrumentation; UiAutomation uiAutomation = instrumentation.getUiAutomation(); mUiAutomationBridge = new InstrumentationUiAutomatorBridge( instrumentation.getContext(), uiAutomation); // Enable multi-window support for API level 21 and up if (UiDevice.API_LEVEL_ACTUAL >= Build.VERSION_CODES.LOLLIPOP) { // Subscribe to window information AccessibilityServiceInfo info = uiAutomation.getServiceInfo(); info.flags |= AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS; uiAutomation.setServiceInfo(info); } }
Example 3
Source File: ImmediateNavigationTest.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Test public void testNavigateInOnResume() throws Throwable { Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); Intent intent = new Intent(instrumentation.getContext(), ImmediateNavigationActivity.class); final ImmediateNavigationActivity activity = mActivityRule.launchActivity(intent); instrumentation.waitForIdleSync(); NavController navController = activity.getNavController(); assertThat(navController.getCurrentDestination().getId(), is(R.id.deep_link_test)); }
Example 4
Source File: EmbeddedXmlTest.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Test public void testRecreate() throws Throwable { Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); Intent intent = new Intent(instrumentation.getContext(), EmbeddedXmlActivity.class); final EmbeddedXmlActivity activity = mActivityRule.launchActivity(intent); instrumentation.waitForIdleSync(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.recreate(); } }); }
Example 5
Source File: MoreKeySpecStringReferenceTests.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); final Instrumentation instrumentation = getInstrumentation(); final Context testContext = instrumentation.getContext(); final Resources testRes = testContext.getResources(); final String testPackageName = testRes.getResourcePackageName(R.string.empty_string); mTextsSet.setLocale(TEST_LOCALE, testRes, testPackageName); }
Example 6
Source File: UnifiedFragmentHelperTest.java From OPFIab with Apache License 2.0 | 5 votes |
private static void reopenActivity(Instrumentation instrumentation) throws InterruptedException { final Context context = instrumentation.getContext(); @SuppressWarnings("deprecation") final Intent intent = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getRecentTasks(2, 0).get(1).baseIntent; intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); instrumentation.getContext().startActivity(intent); Thread.sleep(WAIT_REOPEN_ACTIVITY); }