0

I want to make an android service that would let me simulate keypress to fill fields on a web page when receiving an intent. Is this possible in any way or maybe through a different process (Not by simulation keypress?).

For example an example of what I would want to be able to do.

The user is on his tablet and has selected a field on a web page. For any bluetooth device discovered, fill the field with that id.

IS there a way to do it by calling an intent of the web browser or something like that?

Thanks

EDIT : figured my example was pretty bad.

Here is what I really want to do

When a nfc tag is detected on the phone, read the nfc tag ID, simulate keypress events of the id tag on whatever the focus is at the moment on the phone

Example : I'm on google focused on the search field and I put a nfc tag on the phone, the phone types the Nfc tag id on the google search field and voila

ulkar
  • 99
  • 2
  • 10
  • I don't know true answer of your question, but if you can simulate key press from UI thread, you can use use [handler](http://developer.android.com/reference/android/os/Handler.html) to send messages for perform button clicks – neworld Sep 25 '12 at 15:25
  • Hmmm actually I want to be able to enter text in a browser field without leaving the browser. What I really want to do is : When a nfc tag is detected, read the ID, simulate keypress events of the id tag on whatever the focus is at the moment on the phone – ulkar Sep 25 '12 at 15:27
  • 1
    You can call javscript's form android or vice versa – neworld Sep 25 '12 at 15:31

2 Answers2

1

if you really want to simulate keyevents, you can use system calls:

input keyevent <keycode>
njzk2
  • 38,969
  • 7
  • 69
  • 107
  • Okay, but how would I be able to do so when I'm not in an app, but actually in a web browser such as the default one or chrome – ulkar Sep 25 '12 at 15:35
  • didn't you said you were in a service? – njzk2 Sep 25 '12 at 15:36
  • Yes, but then I read that services on android are linked to an application and not services such as I understood it for example on windows – ulkar Sep 25 '12 at 15:40
  • what? in your case, you probably have some service or something that listens for the nfc thing? when you read something, you transform it in key presses... – njzk2 Sep 25 '12 at 15:47
  • Right ! I didn't get it the first time but it should be what I need ! THanks – ulkar Sep 25 '12 at 15:49
0

I would advice you to use BroadCast receiver. You have to create a Custom intent class after that, register the receiver when the user select a field. For interaction with web page, its better to use javascript to call native android method. When you detect a device send your broadcast, if you are registered, you will handle the event.

Anis BEN NSIR
  • 2,555
  • 20
  • 29
  • Thanks for the answer, my example on the main question was pretty bad so I edited it to reflect more of what I thought – ulkar Sep 25 '12 at 15:33