Simulating mouse clicks from service - android

I am looking forums for two days now and can't find the answer. I am new to android and i have a problem. I need to have a small server service in backround (which i have) that gets coordinates for example. With that coordinates i must simulate (make) a click on the active activity...
It should be service for controling the android from the computer. The computer client aplication sends some information like pressed key or mouse click and the service gets it and performs action on active activity.
Is there any way to do that , some example or something ? Thank you

This is not possible due to obvious security risks.

If you're looking to test your activity, have a look at TouchUtils:
http://developer.android.com/reference/android/test/TouchUtils.html

Related

Is It Possible for an Android App to Ignore All Physical User Input?

I want to try to make an Android alarm app that is impossible to stop. In other words, it keeps going for a predetermined amount of time, even if the user presses the power button, tries to reduce the volume, or anything else.
It does not seem feasible to me, but since I have very little Android experience, I'd like to know if something like that is theoretically able to be done. Thanks.
This question has been addressed on SO here: Override Power button just like Home button
.
There are several answers in the link that will give you options and get you 90% of the way there, but no answer will cover all devices/scenarios. The accepted answer in the link puts it best:
The Android system, as far as is documented, defines (a physical button press) as a
broadcast action. Following the publish-subscribe pattern of message
propagation, this message will notify all concerned parties of this
action. Because this message is sent by the system, because the
message stack is managed by the system, and because the message is
also received by the system, your code simply (cannot be) injected in the
right place to block the reception of this message.

How to start new Activity on trigger, if the App should run in Background

So my question is fairly simple, but I cannot find a solution of the entire idea. Running Android App in background should be achievable with Background Service . However, I am not sure how to make "wake up" the service by a specific button press combination.
DUMMY EXAMPLE:
// My app is installed and launched on the device and is running in background since it got installed
void onCorrectButtonCombinationPressed(){
startActivity(someIntent);
}
How to achieve the above scenario ?
Thanks for suggestions and I apologize if there is something silly that I missed out, because to me it sounds easy to do, but I am struggling to figure it out..
That depends on what you mean by a "specific button press combination"
If you want to detect clicks or button presses from your own activity, then handle it within its respective view through standard event handlers.
if you want to detect clicks or button presses from OTHER activities, give up! There is no means by which you can achieve this through (standard) methods. If you root your device you'll have more power to do something like this, but I did some deep research and found no other ways. The reason for this is because imagine how easy it would be to steal information from activities if you could intercept events being sent to it.
I asked a question the other day that may give you further information.

Select Chromecast media route programmatically

I want to start chromecast routing automatically and not when the user presses the button. Does anyone know how i can simulate in any way that the user pressed the media route button? I have looked through the different classes and not found anything.
I am aware that this is not how Google intends developers to use it, and my application is only functioning as a proof of concept.
If anyone knows another way to achieve the same thing (The casting starts when the app starts, if the user has enabled it in the options menu) - let me know!
You can follow the same steps as usual (get a hold of MediaRouter instance, set a selector, register a callback, etc) but then you need to keep a list of discovered routes in your application (as they are discovered by MediaRouter; you will get a call back via onRouteAdded(()). You need to do the bookkeeping as well (via onRouteRemoved() callback). Now that you have a list of routes, you can programmatically decide which one is the one you want to use and again do as usual (same stuff that you would do when you get a callback via onRouteSelected()) except that you need to call MediaRouter.selectRoute(your_selected_route) yourself to tell the framework about it. For the first part, you can take a look at this sample.
So what I discovered was that I couldn't make a check for routes in the beginning of the program because the MediaRouter hadn't discovered them yet. (I.e the call to getRoutes returned only the default route...) In my program, it was enough to start a thread that sleeps for three seconds and then calls selects any available route:
if(mMediaRouter.getRoutes().size() >= 1) {
mMediaRouter.selectRoute(mMediaRouter.getRoutes().get(1));
}
If I needed a more persistent solution, I'd do as Ali Naddaf suggested.

capture hard-button events when phone is locked?

i am currently collecting information, if it is possible to make some kind of quickdraw-application for emergency purposes; i want to get the device to start a customized camera-intent once some certain key-combo is pressed.
I have check quite some information on the topic already, but it is still not clear to me how doable this whole idea is.
So far i figured, that it is not meant to be by android-design. My first idea was to build some kind of InputService and make it teach the hard power-button to listen for a triple-click. But the Services arent allowed to catch KeyEvents. So, the volume-button is out of the equasion aswell.
Then i came across the idea reacting on the SCREEN ON/OFF event, but 80% of the ppl say that it is not going to work, while 20% state, that they got it. But im not really sure if they really did it.
Last but not least the question, if it is possible to launch this customized-camera-intent/application out of the locked mode.
resumé: i need to check if its possible in general to launch this camera-app (that does some quick fotos for emergency purposes) while phone is in the pocket in lock-mode. Anybody got some opinion for me? thx
The solution is to setup a BroadcastReceiver that is listening for the SCREEN_ON-Event. I did this one inside a backgroundservice that was waiting for at least two SCREEN_ON-Events within a short period of time. (less than two events obviously can't work)...
The Service then dismissed the Keyguard and was able to even pass past password/gesture and run the App. Funny fact: closing the app does pop back to desktop still beeing logged in.
I did this at Android 4.2.. Sources told me that dismissing the keyguard is not working with current Android-versions no more.

Is it possible to make a call from code, and then send keypress events to the dialler?

OK I want to be able test internal phone systems in an automated fashion using an Android app, the requirements are asking for an app which can initiate a call programatically. If this is possible then when the call starts they wish to be able to send key presses, like imagine the phone menu says "press 5 to get to the X menu".. can we send that keypress from code? This way the whole system could be tested with a series of waits, and keypresses sent to the dialler.
I'm not sure how to find out if this is actually possible.. I saw PROCESS_OUTGOING_CALLS, but I havent been able to find any resources or examples on doing this, does anyone have any information? I actually got in touch with a freelancer who ended up saying it was definitely not possible (he's pretty good and he simply said 'pressing dialpad during call was impossible'), but my client is telling me apps already exist to do this, so any tips would be helpful!..
You can definitely make a call from code. See:
How to make a phone call programmatically?
You can invoke key presses from code as well:
Invoke keypress event in android?
As for doing it during a call, I haven't tried this, But you can try it using the methods from the links. Good luck!

Categories

Resources