Java Code Examples for android.app.Instrumentation#startActivitySync()
The following examples show how to use
android.app.Instrumentation#startActivitySync() .
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: CameraStartUp.java From Camera2 with Apache License 2.0 | 6 votes |
private long launchCamera() { long startupTime = 0; try { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); long beforeStart = System.currentTimeMillis(); Instrumentation inst = getInstrumentation(); Activity cameraActivity = inst.startActivitySync(intent); long cameraStarted = System.currentTimeMillis(); Thread.sleep(WAIT_TIME_FOR_PREVIEW); cameraActivity.finish(); startupTime = cameraStarted - beforeStart; Thread.sleep(1000); Log.v(TAG, "camera startup time: " + startupTime); } catch (Exception e) { Log.v(TAG, "Got exception", e); fail("Fails to get the output file"); } return startupTime; }
Example 2
Source File: CameraStartUp.java From Camera2 with Apache License 2.0 | 6 votes |
private long launchVideo() { long startupTime = 0; try { Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); long beforeStart = System.currentTimeMillis(); Instrumentation inst = getInstrumentation(); Activity recorderActivity = inst.startActivitySync(intent); long cameraStarted = System.currentTimeMillis(); recorderActivity.finish(); startupTime = cameraStarted - beforeStart; Log.v(TAG, "Video Startup Time = " + startupTime); // wait for 1s to make sure it reach a clean stage Thread.sleep(WAIT_TIME_FOR_PREVIEW); Log.v(TAG, "video startup time: " + startupTime); } catch (Exception e) { Log.v(TAG, "Got exception", e); fail("Fails to launch video output file"); } return startupTime; }
Example 3
Source File: ImageCapture.java From Camera2 with Apache License 2.0 | 5 votes |
public void testBackImageCapture() throws Exception { Instrumentation inst = getInstrumentation(); Intent intent = new Intent(); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRAS_CAMERA_FACING, android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); Activity act = inst.startActivitySync(intent); Thread.sleep(WAIT_FOR_SWITCH_CAMERA); captureImages("Back Camera Image Capture\n", inst); act.finish(); }
Example 4
Source File: ImageCapture.java From Camera2 with Apache License 2.0 | 5 votes |
public void testFrontImageCapture() throws Exception { Instrumentation inst = getInstrumentation(); Intent intent = new Intent(); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRAS_CAMERA_FACING, android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); Activity act = inst.startActivitySync(intent); Thread.sleep(WAIT_FOR_SWITCH_CAMERA); captureImages("Front Camera Image Capture\n", inst); act.finish(); }
Example 5
Source File: VideoCapture.java From Camera2 with Apache License 2.0 | 5 votes |
public void testBackVideoCapture() throws Exception { Instrumentation inst = getInstrumentation(); Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRAS_CAMERA_FACING, android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); Activity act = inst.startActivitySync(intent); Thread.sleep(WAIT_FOR_SWITCH_CAMERA); captureVideos("Back Camera Video Capture\n", inst); act.finish(); }
Example 6
Source File: VideoCapture.java From Camera2 with Apache License 2.0 | 5 votes |
public void testFrontVideoCapture() throws Exception { Instrumentation inst = getInstrumentation(); Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRAS_CAMERA_FACING, android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); Activity act = inst.startActivitySync(intent); Thread.sleep(WAIT_FOR_SWITCH_CAMERA); captureVideos("Front Camera Video Capture\n", inst); act.finish(); }
Example 7
Source File: ExampleActivityTest.java From androidnative.pri with Apache License 2.0 | 5 votes |
private void startActivity() { if (launched) return; Instrumentation instrumentation = getInstrumentation(); Intent intent = new Intent(getInstrumentation() .getTargetContext(), AndroidNativeActivity.class); intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); mActivity = instrumentation.startActivitySync(intent); launched = true; instrumentation.waitForIdleSync(); sleep(5000); }
Example 8
Source File: ActivityRule.java From AndroidEspressoIdlingResourcePlayground with MIT License | 5 votes |
@SuppressWarnings("unchecked") // Guarded by generics at the constructor. public void launchActivity() { if(activity != null) { return; } Instrumentation instrumentation = fetchInstrumentation(); String targetPackage = instrumentation.getTargetContext().getPackageName(); Intent intent = getLaunchIntent(targetPackage, activityClass); activity = (T) instrumentation.startActivitySync(intent); instrumentation.waitForIdleSync(); }
Example 9
Source File: AppInteractor.java From edx-app-android with Apache License 2.0 | 5 votes |
public AppLaunchInteractor launchApp() { final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); final Intent launchIntent = instrumentation.getTargetContext().getPackageManager() .getLaunchIntentForPackage(instrumentation.getTargetContext().getPackageName()) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); instrumentation.startActivitySync(launchIntent); instrumentation.waitForIdleSync(); return new AppLaunchInteractor(); }
Example 10
Source File: ActivityRule.java From u2020-mvp with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") // Guarded by generics at the constructor. private void launchActivity() { if (activity != null) return; Instrumentation instrumentation = fetchInstrumentation(); String targetPackage = instrumentation.getTargetContext().getPackageName(); Intent intent = getLaunchIntent(targetPackage, activityClass); activity = (T) instrumentation.startActivitySync(intent); instrumentation.waitForIdleSync(); }