How to use Android clipboard in Python scripts

0

I'm doing some tests for an Android script. It is a series of randomly generated numbers that automatically and without displaying anything on the screen, go to the clipboard and is available to be copied anywhere. For now, I run without problem the following piece of code in Windows that performs the function of data entry to the clipboard.

#Introducción automática del mensaje string a clipboard
import os
def addToClipBoard(text):
    command = 'echo ' + text.strip() + '| clip'
    os.system(command)

addToClipBoard(result2)

However, I am not able to know how to do this on Android. I've seen that Androidhelper has a function (setClipboard)

  

setClipboard (text) Put text in the clipboard. text (String) Creates a new     AndroidFacade that simplifies the interface to various Android APIs.

I'm doing the executions with QPython3.2. Can someone give me a cable?

EDIT: I have solved it in the following way:

from androidhelper import Android
droid = Android()
#setClipboard
droid.setClipboard("Hello World")
#getClipboard
clipboard = droid.getClipboard().result
    
asked by DDR2348 02.10.2018 в 13:39
source

1 answer

0

QPython does not support all Python features, especially those that require direct interaction with the OS. What you can do in this case is to use SL4A using the androidhelper module as you comment:

import androidhelper

droid = androidhelper.Android()
droid.setClipboard("Hola Python!")

androidhelper interacts with SL4A using the class Android , which has setClipboard as the instance method. You just have to create an instance of it previously to use it therefore.

  

Note: To make it work properly, you must make sure you have activated SL4A:

     

    
answered by 02.10.2018 в 17:12