当前位置: 首页>>代码示例>>Java>>正文


Java UiObject.getPackageName方法代码示例

本文整理汇总了Java中com.android.uiautomator.core.UiObject.getPackageName方法的典型用法代码示例。如果您正苦于以下问题:Java UiObject.getPackageName方法的具体用法?Java UiObject.getPackageName怎么用?Java UiObject.getPackageName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.uiautomator.core.UiObject的用法示例。


在下文中一共展示了UiObject.getPackageName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start_target_app

import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
private void start_target_app(String appName) throws UiObjectNotFoundException {
		// 0. Start fromIndex HOME
		dev.pressHome();

		// 1. Find and click "Apps" button
		//NO Need to use that
//		UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
//
//		allAppsButton.clickAndWaitForNewWindow();

		// 2. Find and click “Apps” tab
		UiObject appsTab = new UiObject(new UiSelector().description("Apps"));
		if (launcherPackName == null) {
			launcherPackName = appsTab.getPackageName(); // remember the launcher package
		}
		appsTab.click();

		// 3. Select scrollable "container view" 
		UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
		// Set the swiping mode to horizontal (the default is vertical)
		appViews.setAsHorizontalList();

		// 4. This API does not work properly in 4.2.2 
		appViews.scrollTextIntoView(appName);

		// 5. Click target app
		UiObject targetApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), appName, true);

		boolean done = targetApp.clickAndWaitForNewWindow();

		waitForNetworkUpdate();
		// AccessibilityEventProcessor.waitForLastEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, WINDOW_CONTENT_UPDATE_TIMEOUT);
	}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:34,代码来源:EnhancedPUMALauncher.java

示例2: start_target_app

import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
private void start_target_app() throws UiObjectNotFoundException {
	// 0. Start fromIndex HOME
	dev.pressHome();

	// 1. Find and click "Apps" button
	// TODO: this is ad hoc fix for CM-10.2 nightly snapshot only
	UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));

	//		int cnt = 0;
	//		boolean end = false;
	//		while (!end) {
	//			UiObject obj = new UiObject(new UiSelector().packageName("com.cyanogenmod.trebuchet").className("android.widget.TextView").instance(cnt));
	//			cnt++;
	//
	//			try {
	//				obj.getBounds();
	//			} catch (UiObjectNotFoundException exception) {
	//				end = true;
	//			}
	//		}
	//		Util.log("HOME: " + (cnt - 1) + " TextViews");
	//
	//		if ((cnt - 1) < 5) {
	//			Util.err("ERR: NOT_AT_HOME");
	//			System.exit(-1);
	//		}
	//
	//		// Now there are (cnt-1) TextViews, "Apps" should be the (cnt-4)-th.
	//		UiObject allAppsButton = new UiObject(new UiSelector().packageName("com.cyanogenmod.trebuchet").className("android.widget.TextView").instance(cnt - 4));
	allAppsButton.clickAndWaitForNewWindow();

	// 2. Find and click “Apps” tab
	if (android.os.Build.VERSION.SDK_INT < 21) {
		//Add by Ruiyi He to avoid "Apps" cause in 5.0 this feature didnt exist
		UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
		launcherPackName = appsTab.getPackageName(); // remember the launcher package
		appsTab.click();
	}
	

	// 3. Select scrollable "container view" 
	UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
	// Set the swiping mode to horizontal (the default is vertical)
	appViews.setAsHorizontalList();

	// 4. This API does not work properly in 4.2.2 
	appViews.scrollTextIntoView(appName);

	// 5. Click target app
	UiObject targetApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), appName, true);

	boolean done = targetApp.clickAndWaitForNewWindow();
	// Util.log("clickAndWaitForNewWindow: " + done);

	waitForNetworkUpdate();
	// AccessibilityEventProcessor.waitForLastEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, WINDOW_CONTENT_UPDATE_TIMEOUT);
}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:58,代码来源:LaunchApp.java


注:本文中的com.android.uiautomator.core.UiObject.getPackageName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。