標籤:
擷取包名、開啟通知欄、快速設定、擷取布局檔案的方法
一、包名、通知欄、快速設定、布局檔案等相關知識:
1)包名:標示應用的符號,每個應用的名字
2)通知欄:從主介面的頂端向下拉,就可以開啟通知欄
3)快速設定:開啟通知欄,右上方有個設定,快速設定可以進行設定、無線網路等等
4)布局檔案:介面布局的檔案,顯示介面各個控制項元素資訊的檔案
二、相關API:
| 傳回值 |
包名 |
描述 |
| void |
getCurrentPackageName() |
擷取當前介面的包名 |
| void |
dumpWindowHierarchy(String fileName) |
擷取當前介面的布局檔案,儲存在/data/local/tmp目錄下 |
| boolean |
openNotification() |
開啟通知欄 |
| boolean |
openQuickSettings() |
開啟快速設定欄 |
三、相關API應用舉例:
package com.uiautomatortest;import java.io.File;import android.graphics.Point;import android.os.Bundle;import android.os.RemoteException;import android.view.KeyEvent;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.testrunner.UiAutomatorTestCase;public class Test extends UiAutomatorTestCase { public void testPackage(){ String packageName=UiDevice.getInstance().getCurrentPackageName(); System.out.println("PackageName is: "+packageName); } public void testNotificationAndQuikSettings(){ UiDevice.getInstance().pressHome(); UiDevice.getInstance().openNotification(); sleep(2000); UiDevice.getInstance().openQuickSettings(); sleep(2000); UiDevice.getInstance().dumpWindowHierarchy("QuickSetings.xml"); }}Test.java
Android無線測試之—UiAutomator UiDevice API介紹八