Android Instrumentation - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Instrumentation class.

This code example shows how to use the following methods: sendKeySync
        // foreground, and steal UI focus 
        // unfortunately this means the next key event will get directed to the 
        // 'volume adjustment' UI, instead of this test's activity 
        // for this reason this test must be signed with platform certificate, to grant this test 
        // permission to inject key events to another process 
        getInstrumentation().sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
                KeyEvent.KEYCODE_VOLUME_DOWN));
        getInstrumentation().sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
                KeyEvent.KEYCODE_POWER));
    } 
 
    /** 
     * Get the directory where screenshot images are stored. 
     */ 
    private File getScreenshotDir() {
        // TODO: get this dir location from a constant 
        return new File(Environment.getExternalStorageDirectory(), "Pictures" + File.separator +
                "Screenshots"); 
    } 
 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getTargetContext
     * 
     * @param instrumentation 
     */ 
    public BootstrapApplication(final Instrumentation instrumentation) {
        this(); 
        attachBaseContext(instrumentation.getTargetContext());
    } 
 
    public static BootstrapApplication getInstance() { 
        return instance;
    } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: callActivityOnPause, callActivityOnResume, sleep
    } 
     
 
    public void testPauseAndResume() 
    { 
        mInstr.callActivityOnPause(testActivity);
        sleep(); 
        assertTrue(testView.isPaused());
        mInstr.callActivityOnResume(testActivity);
        sleep(); 
        assertFalse(testView.isPaused());
    } 
     
    private void sleep() { 
        try { 
          Thread.sleep(TIMEOUT);
        } catch (InterruptedException e) {
          fail("Unexpected Timeout");
        } 
    } 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: startActivitySync, getFlags, setFlags
        instrumentation.sendStringSync("s");
        poseForScreenshotNamed("ConfigureMorseActivity-SOS"); 
    } 
 
    private <T extends Activity> T startActivitySync(Class<T> clazz) {
        Intent intent = new Intent(getInstrumentation().getTargetContext(), clazz);
        intent.setFlags(intent.getFlags() | FLAG_ACTIVITY_NEW_TASK);
        return (T) getInstrumentation().startActivitySync(intent);
    } 
 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getTargetContext
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android Instrumentation Questions & Answers:

See Code Examples for Android Instrumentation Methods: