在 Android 模拟器上粘贴文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3391160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:59:58  来源:igfitidea点击:

Paste text on Android Emulator

androidcopy-paste

提问by ankitjaininfo

Is there an easy way to copy/paste (desktop's) clipboard content to EditViewon Android Emulator?

有没有一种简单的方法可以将(桌面的)剪贴板内容复制/粘贴到EditViewAndroid 模拟器上?

(just for the sake to ease development/test)

(只是为了简化开发/测试)

采纳答案by Jamal Eason

With v25.3.x of the Android Emulator & x86 Google API Emulator system images API Level 19 (Android 4.4 - Kitkat) and higher, you can simply copy and paste from your desktop with your mouse or keyboard.

使用 v25.3.x 的 Android 模拟器和 x86 Google API 模拟器系统映像 API 级别 19 (Android 4.4 - Kitkat) 及更高版本,您只需使用鼠标或键盘从桌面复制和粘贴即可。

This feature was announced with Android Studio 2.3

此功能是在Android Studio 2.3 中宣布的

Copy and Paste with the Android Emulator

使用 Android 模拟器复制和粘贴

回答by Rose Perrone

In a terminal, type adb shell input text 'my string here. With some characters escaped like \$ that'

在终端中,输入 adb shell input text 'my string here. With some characters escaped like \$ that'

Note that an alternative method for including spaces in the text is to substitute %sfor each spacecharacter.

请注意,在文本中包含空格的另一种方法是替换%s每个space字符。

回答by Joel Beckham

I usually send the text I want to copy as an sms message through telnet and then copy the text from the sms message. Here's how:

我通常通过telnet将我想复制的文本作为短信发送,然后从短信中复制文本。就是这样:

Connect through telnet:

通过telnet连接:

  • Syntax:telnet localhost <port>
  • Example:telnet localhost 5554
  • 句法:telnet localhost <port>
  • 例子:telnet localhost 5554

(5554 is the default port. The title bar of the emulator shows the port that is being used, so you can see if it's different).

(5554是默认端口。模拟器的标题栏显示了正在使用的端口,所以你可以看看它是否不同)。

Send message:

发信息:

  • Syntax:sms send <senders phone number> <message>
  • Example:sms send 1231231234 This is the message you want to send
  • 句法:sms send <senders phone number> <message>
  • 例子:sms send 1231231234 This is the message you want to send

(You can just make up the senders phone number)

(你可以只补发件人的电话号码)

This works really well for links as the message is automatically converted into a hyperlink which you can click without having to copy / paste it into the browser.

这对于链接非常有效,因为消息会自动转换为超链接,您无需将其复制/粘贴到浏览器中即可点击。

Once the emulator receives the message you can copy it and paste it wherever you like.

模拟器收到消息后,您可以将其复制并粘贴到您喜欢的任何位置。

回答by Raymond Wachaga

Just copy from wherever, click and hold on the emulator phone's edit text where you want the text to go (kind of like you would press and hold to paste on an actual phone), the PASTE option will appear, then PASTE.

只需从任何地方复制,在模拟器手机的编辑文本上单击并按住您想要文本的位置(有点像您在实际手机上按住粘贴),将出现粘贴选项,然后粘贴。

回答by TEH EMPRAH

Not sure if that's useful, but, if you need a long URL from desktop browser to be opened in mobile browser, you can send SMS with that URL and open directly from message app.

不确定这是否有用,但是,如果您需要在移动浏览器中打开桌面浏览器中的长 URL,您可以使用该 URL 发送 SMS 并直接从消息应用程序打开。

enter image description here

在此处输入图片说明

回答by Andrew

If you are using Android Studio on a Mac, you may need to provide the full path to the adbexecutable. To find this path, open:

如果您在 Mac 上使用 Android Studio,则可能需要提供adb可执行文件的完整路径。要找到此路径,请打开:

Android Studio > Tools > Android > SDK Manager

Copy the path to the SDK location. The adbexecutable will be within a platform-toolsdirectory. For me, this was the path:

将路径复制到 SDK 位置。该adb可执行文件将是一个内platform-tools目录。对我来说,这是路径:

~/Library/Android/sdk/platform-tools/adb

Now you can run this command:

现在你可以运行这个命令:

~/Library/Android/sdk/platform-tools/adb shell input text 'thetextyouwanttopaste'

回答by gMale

I got tired of this problem so I just made this alias to handle it:

我厌倦了这个问题,所以我做了这个别名来处理它:

alias ap="pbpaste | xargs adb shell input text"

Then when you open a new terminal window, typing "ap" will paste whatever is on your clipboard into the emulator's actively selected text field.

然后,当您打开一个新的终端窗口时,输入“ap”会将剪贴板上的任何内容粘贴到模拟器主动选择的文本字段中。

Setup

设置

Simply add this to your profile (for most users that's ~/.bash_profilefor zsh users that's ~/.zshrc) to make the alias available everywhere. Alternatively, if you're a bash user (the default for MacOS), then you can run the following command in the terminal to set it up for you:

只需将此添加到您的个人资料中(对于大多数用户,即~/.bash_profilezsh 用户~/.zshrc),即可在任何地方使用别名。或者,如果您是 bash 用户(MacOS 的默认用户),那么您可以在终端中运行以下命令为您进行设置:

echo "alias ap='pbpaste | xargs adb shell input text'" >> ~/.bash_profile && source ~/.bash_profile

回答by nana janashia

You can do this without workarounds too. Just click and hold for a bit in the input field till the paste notification appears and then click on paste. That's it!

您也可以在没有变通方法的情况下执行此操作。只需在输入字段中单击并按住一会儿,直到出现粘贴通知,然后单击粘贴。就是这样!

回答by Rishabh Arya

Only For API level >= 24

仅适用于 API 级别 >= 24

Copy any text from your local machine and then simply run this command

从本地机器复制任何文本,然后只需运行此命令

adb shell input keyevent 279

Make sure In Android Emulator Settings the Enable Clipboard Sharingoptions is enabled

确保在 Android Emulator SettingsEnable Clipboard Sharing中启用了选项

回答by mad

maybe a little bit tricky, but you could send an sms to the emulator by using the emulator control. then you do not have to retype all the text if it is longer and can copy-paste it in the emulator.

也许有点棘手,但您可以使用模拟器控件向模拟器发送短信。那么如果文本较长,您就不必重新键入所有文本,并且可以将其复制粘贴到模拟器中。

another way: connect to emulator via "telnet localhost PORT" and then use hardware event sending to send a text input event to the emulator (needs to be UTF-8). look at this

另一种方式:通过“telnet localhost PORT”连接到模拟器,然后使用硬件事件发送将文本输入事件发送到模拟器(需要是 UTF-8)。看看这个