本文整理汇总了Java中android.app.Instrumentation.getTargetContext方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.getTargetContext方法的具体用法?Java Instrumentation.getTargetContext怎么用?Java Instrumentation.getTargetContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Instrumentation
的用法示例。
在下文中一共展示了Instrumentation.getTargetContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWriteableDir
import android.app.Instrumentation; //导入方法依赖的package包/类
/**
* 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);
}
示例2: setUpScreenshots
import android.app.Instrumentation; //导入方法依赖的package包/类
@Before
public void setUpScreenshots() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
targetContext = instrumentation.getTargetContext();
device = UiDevice.getInstance(instrumentation);
// Use this to switch between default strategy and HostScreencap strategy
//Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
Screengrab.setDefaultScreenshotStrategy(new HostScreencapScreenshotStrategy(device));
device.waitForIdle();
}
示例3: startTestActivity
import android.app.Instrumentation; //导入方法依赖的package包/类
private TestActivity startTestActivity(final Instrumentation instrumentation) {
final Intent intent = new Intent(instrumentation.getTargetContext(), TestActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return (TestActivity) instrumentation.startActivitySync(intent);
}