简体   繁体   English

如何在Calabash-android中将应用程序带到Foreground?

[英]How to bring app to Foreground in calabash-android?

I am working on a application, it contain social share options. 我正在开发一个应用程序,它包含社交共享选项。 Whenever I tap on facebook it will open facebook app in the device with share view. 每当我点击facebook时,它将在带有共享视图的设备中打开facebook应用程序。

After that, I want to bring my application to foreground. 之后,我想将我的应用程序置于前台。

I tried pressing back button, 我尝试按返回按钮,

press_back_button()

it is unsuccessful. 这是不成功的。

Is there any way to bring application to foreground in Calabash-android? 有什么办法可以将应用程序带到Calabash-android的前台?

You should be able to do it by sending keypresses and screen touches with ADB 您应该可以通过使用ADB发送按键和屏幕触摸来做到这一点

adb shell input keyevent KEYCODE_APP_SWITCH to open the recent apps menu adb shell input tap 300 300 adb shell input keyevent KEYCODE_APP_SWITCH打开最近的应用程序菜单adb shell input tap 300 300 adb shell input keyevent KEYCODE_APP_SWITCH

Will send a tap event on the screen but you'll have to play around with the coordinates to get them in the right place. 将在屏幕上发送轻击事件,但您必须试着调整坐标才能将其放置在正确的位置。

EDIT: I just tried on my phone with the following commands and can reopen the most recent app 编辑:我刚刚在手机上尝试使用以下命令,并且可以重新打开最新的应用程序

adb shell input keyevent KEYCODE_APP_SWITCH
adb shell input tap 300 1700

Before trying these commands on your ruby code see if they work from the terminal (not irb). 在Ruby代码上尝试这些命令之前,请先查看它们是否可以从终端(不是irb)运行。

The second command uses x and y coordinates that will be different depending on the size of the screen on your phone, 300 1700 works for me but you will need to try some different numbers to make it work for you. 第二个命令使用x和y坐标,这些坐标将根据手机屏幕的尺寸而有所不同。300 1700对我有用,但是您需要尝试一些不同的数字才能使其适合您。

To open the second most recent app, which I think is what you will need, I have to run adb shell input tap 300 700 . 要打开第二个最新的应用程序,我认为这是您所需要的,我必须运行adb shell input tap 300 700 You will need to play around with this and see what works for you. 您将需要解决这一问题,并查看适合您的方法。

FINAL EDIT: I've found a nicer way to do this that's not dependant on screen resolution. 最终编辑:我发现了一种更好的方法,它不依赖于屏幕分辨率。

adb shell input keyevent KEYCODE_APP_SWITCH

Then to find your app (you may need to send these multiple times to get it to work) 然后找到您的应用(您可能需要多次发送这些信息才能使其正常工作)

adb shell input keyevent KEYCODE_DPAD_UP

and/or 和/或

adb shell input keyevent KEYCODE_DPAD_DOWN

Then to select 然后选择

adb shell input keyevent KEYCODE_ENTER

您需要运行系统命令,例如system(“ adb shell input keyevent KEYCODE_APP_SWITCH”)这将打开最近的活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM