Как отправить текст в текстовое поле (в другом приложении) с помощью Broadcast Receiver - PullRequest
0 голосов
/ 25 октября 2019

Я использую встроенный сканер штрих-кода на устройстве Android. Когда я использую сканер, я использую метод onReceive в BroadcastReceiver, чтобы получить строку штрих-кода.

Затем я хочу отправить строку в текущее выбранное текстовое поле. Текстовое поле не будет содержаться в приложении сканера. Например, я нажимаю на текстовое поле URL в Google Chrome, а затем сканирую книгу. ISBN книги должен появиться в текстовом поле URL.

Вот мой onReceive Override

@Override
    public void onReceive(Context context, Intent intent) {

        byte[] barocode = intent.getByteArrayExtra("barocode");
        int barocodelen = intent.getIntExtra("length", 0);
        byte temp = intent.getByteExtra("barcodeType", (byte) 0);
        byte[] aimid = intent.getByteArrayExtra("aimid");
        String barcodeStr = new String(barocode, 0, barocodelen);

        //fullBarcode is the string received from the scanner
        //with the added prefix and suffix (`)
        String fullBarcode = "`" + barcodeStr + "`";

        Log.d("BARCODE", fullBarcode);

        //Here I want to send the fullBarcode string to whatever
        //text box is currently selected

    }
...