本文整理匯總了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);
}