c#shell android,将常用的Android adb shell 命令行封装为C#静态函数

唤醒 安卓 Apk:

public static bool WakeupAndroidApk( string activity)

{

string output = GetCmdOutput("adb shell \"am start -n " + activity + "\"");

return output.Contains("Success" );

}

关闭当前 应用:

public static bool closeCurrentActivity( string activity)

{

string output = GetCmdOutput("adb -s " + udid + " shell \"pm clear " + activity);

return output.Contains("Success" );

}

按屏幕坐标点击:

public static void Tap( int X, int Y)

{

GetCmdOutput( String.Format("adb -s {0} shell input tap {1} {2}" , udid, X, Y));

}

检查当前 应用:

public static bool CheckCurrentActivity( string activity)

{

string output = GetCmdOutput("adb -s " + udid + " shell \"dumpsys activity \"");

string[] lines = output.Split('\n' );

string target = "" ;

Regex reg = new Regex( ".*mFocusedActivity.*");

foreach(string line in lines)

{

if (reg.IsMatch(line))

{

target = line;

break;

}

}

return target.Contains(activity);

}

///

/// 打开指定浏览器

///

/// 浏览器

public static void OpenSpecialBrowser( string browserAndroidApk)

{

GetCmdOutput( "adb -s " + udid + " shell am start " + browserAndroidApk);

}

///

/// 按手机屏幕坐标点击

///

/// x坐标

/// y坐标

public static void Tap( int x, int y)

{

GetCmdOutput( "adb -s " + udid + " shell input tap " + x + " " + y);

}

public static void Tab()

{

GetCmdOutput( "adb -s " + udid + " shell input keyevent 61" );

}

///

/// 输入keyevent值对应的字符

///

/// keyevent值

public static void Tab( string key)

{

GetCmdOutput( "adb -s " + udid + " shell input keyevent " + "key");

}

///

/// 输入URL地址

///

/// URL地址

public static void InputURL( string URL)

{

GetCmdOutput( "adb -s " + udid + " shell input text " + URL);

}

public static void Enter()

{

GetCmdOutput( "adb -s " + udid + " shell input keyevent 66" );

}

///

/// 清理指定的浏览器

///

/// 浏览器

public static void ClearBrowser( string browserAndroidApk)

{

GetCmdOutput( "adb -s " + udid + " shell pm clear " + browserAndroidApk);

}

///

/// 卸载指定的App

///

/// App

public static void UninstallApp( string APPAndroidApk)

{

GetCmdOutput( "adb -s " + udid + " uninstall " + APPAndroidApk);

}

///

/// 关闭当前进程Activity

///

/// Activity

/// 返回清理结果

public static bool closeCurrentActivity( string activity)

{

string output = GetCmdOutput("adb -s " + udid + " shell \"pm clear " + activity);

return output.Contains("Success" );

}

感谢阅读,作者原创技术文章,转载请注明出处

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值