java.lang.RuntimeException: Waited for the root of the vIEw hIErarchy to have window focus and not be requesting layout for over 10 seconds.
在运行测试之前,我似乎需要解锁仿真器屏幕.为此,我必须使用所需权限向src / deBUG添加清单,然后使用以下命令解锁屏幕:
KeyguardManager mKeyguardManager = (KeyguardManager) ctx.getSystemService(Context.KEyguard_SERVICE);KeyguardManager.keyguardlock mlock = mKeyguardManager.newkeyguardlock(name);mlock.disableKeyguard();
问题是我不想乱丢我的活动,上面的代码包含在if块中.有没有办法从浓缩咖啡测试中解锁屏幕?
我的浓咖啡测试:
@RunWith(AndroIDJUnit4.class)public class EspressoSetupTest { @Rule public final ActivityTestRule<WelcomeActivity> activity = new ActivityTestRule<>(WelcomeActivity.class,true,true); @Test public voID launchtest() { onVIEw(withID(R.ID.welcome_textVIEw_hello)) .perform(click()) .check(matches(withText("Retrolambda is working"))); }}解决方法 您可以在Espresso Test中使用setUp()方法,如:
@UiThreadTest@Beforepublic voID setUp() throws Exception { final Activity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @OverrIDe public voID run() { KeyguardManager mKG = (KeyguardManager) activity.getSystemService(Context.KEyguard_SERVICE); KeyguardManager.keyguardlock mlock = mKG.newkeyguardlock(KEyguard_SERVICE); mlock.disableKeyguard(); //turn the screen on activity.getwindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_disMISS_KEyguard | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); } });}
SRC /调试/ AndroIDManifest.xml中
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" > <uses-permission androID:name="androID.permission.disABLE_KEyguard"/> <uses-permission androID:name="androID.permission.WAKE_LOCK"/></manifest>总结
以上是内存溢出为你收集整理的android – 使用浓缩咖啡解锁仿真器屏幕全部内容,希望文章能够帮你解决android – 使用浓缩咖啡解锁仿真器屏幕所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)