使用Android UiAutomator解锁手势密码
2016-09-13 18:59
375 查看
package com.jane.demofortest; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.Point; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.By; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.Until; import static org.hamcrest.CoreMatchers.notNullValue; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertThat; /** * Created by jane on 16/9/13. */ @RunWith(AndroidJUnit4.class) public class UnitTestDemo { private static final String BASIC_SAMPLE_PACKAGE = "com.jane.example"; private static final int LAUNCH_TIMEOUT = 10000; UiDevice mDevice; @Before public void setUp() throws Exception{ // Initialize UiDevice instance mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); // Launch the blueprint app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager() .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances context.startActivity(intent); // Wait for the app to appear // mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); Thread.sleep(LAUNCH_TIMEOUT); } private String getLauncherPackageName() { // Create launcher Intent final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); // Use PackageManager to get the launcher package name PackageManager pm = InstrumentationRegistry.getContext().getPackageManager(); ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); return resolveInfo.activityInfo.packageName; } @Test public void test_login(){ System.out.println("Test Begin"); mDevice.swipe(new Point[]{new Point(190,659),new Point(547,655),new Point(547,1018),new Point(540,1370),new Point(900,1359)},6);//这段是解锁手势密码 } }
不知道为什么:mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
这里会报空指针的错误,有大神给指点下吗?
相关文章推荐
- Android仿支付宝手势密码解锁功能
- Android自定义View九宫格手势密码解锁
- Android 手势解锁详解(包括一次解锁、二次设置密码)
- 自定义View----Android九宫格手势密码解锁
- Android 手势解锁 GestureLock的使用和简单修复
- Android 5秒学会使用手势解锁功能
- Android手势密码解锁设计
- 自定义View----Android九宫格手势密码解锁
- Android手势密码解锁
- Android实现利用手势完成屏幕密码锁功能
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
- Android Gesture 手势识别使用实例
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- android2.2中默认浏览器无法使用手势放大缩小页面的问题定位
- Android Gesture手势识别使用实例
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动