How to "control" a call in android? - java

im developing an app where one should be able to call and "reject" a call from the desktop using a small socket program to communicate with the phone over USB.
I got most of it in place, I can call a number from my desktop application, however, when a call is being made it is not under control of the application.
I run a service which starts a server socket thread, and then I bind the local listen port to my computer with adb forward tcp. When I send a CALL:123123 it will start a new call intent that calls the number "123123".
How would I go about making a call and then at some point ending it again?

I'm almost sure this is not possible to do programatically. Android doesn't let programs make manipulate phone calls without some user interaction due to security concerns.

Related

Android: have app send request to another app over network (on other phone)

I have two apps: "app" and "receiver", the latter of which also runs as a service on the phone. These are designed to be run on two separate phones - only one receiver will ever exist, which will be on my phone.
I'll try to make the problem as simple as I can: from the app, I'd like to be able to press a button saying 'hello', which would then load up an activity on the receiver's phone (from the service) also saying 'hello'. Pretty much I just don't know how to get the two devices to talk to each other. This will only be used over the same Wi-Fi connection. Would a broadcast be a suitable way to do this?
I've just started Android development a few days ago so I'm not sure how to do it - it's probably simple - and any help will be massively appreciated!
Many thanks!
Would a broadcast be a suitable way to do this?
No. Broadcasts can be used for inter-app communication, not inter-device communication.
Instead, devices on the same LAN can adress each other using their local IPs (usually 192.168.x.x).
One option would be to open a socket connection, see how to create Socket connection in Android?

Streaming a python game through a jsp

So im creating this game using pygame, and i have to put it up on a website, but it has to run server-side since the game is gonna be using a database locally, and the client will be able to enter a web page and click on a button and the game is gonna run, i cant make the game run completely client side because then the game wont be able to connect to my local database
Any ideas?
The way I see it you have two options:
If network connection is intermittent (not so frequent), you can use javascript (AJAX specifically) to make HTTP calls to the server whenever you need to access your database.
If you are expecting frequent (continuous) requests (i.e. multiplayer games), you would need to keep a connection alive using either
Persistent HTTP request
TCP Socket
Websocket : You probably want to use this if you want cross-browser support.
Let me know if you have any other questions regarding the options above.

Constant connection android sockets

I've been researching stackoverflow for days now, but can't seem to find a problem like mine.
I have an Raspberry Pi with a python socket server listening for incoming messages. Also I have a Android app which connects to it.
My idea was to create a "simple" music player on the raspberry pi with the use of the pygame module. You can see the Android app as the controller of the music player (Sonos like).
I already have a start, connecting the Android app with Raspberry pi is not the problem.
It's more how the communication between the two need to flow.
A few "solutions" I already thought about:
At the moment the Android app creates a socket object and connection in a new Thread then closes the Thread (so the Thread doesn't receive or sends messages, but the socket persists). When the user clicks a button (let's say to update the music list), it opens a new Thread then uses the already created socket object to send a command, gets a response and updates the UI then terminates the Thread again. And I do this for every action that needs to happen (play, pause, stop, etc.) With this method only the Android app has the right to ask for an action, because it's not constantly listening for server messages
So what if I would create a single thread which is in a constant loop sending a message and then getting a response: how do I interact with the loop from the main UI thread (like clicking a button). I thought about a synchronized List<String> MessageQueue where the main thread pushes a command and in the connection thread's while loops it checks if there are any messages that need to be send.
I made a little schema, how I had this in mind:
Schema (single thread with while loop):
single thread with while loop
Also the reason I chose sockets and not just a simple HTTP request is because later on want to update the UI so you can see real-time music playing (with the seconds updating and stuff like almost every musicplayer has, and who knows what more.
If you guys have any idea's, or know of any topics, example applications on how to create this then please share! If some things are not clear or are a little vague, feel free to ask/comment because I just started with asking on forums.
Example applications that use persistent socket connections with real-time communication are also welcome!
side question: would JSON be a good way to communicate between the 2 applications?
like this:
{
currentsong: "song1.mp3"
position: "1.30" // The current position the music is playing on the server
songlist: ["song1.mp3","song2.mp3","song4.mp3"]
...
}

Implementing virtual keyboard for PC

I am going to implement an android virtual keyboard for controlling PC.
Here is scheme how I want this application to work:
Phone app connects to running client on the pc.
User press button on the phone.
App sends to client signal indicating what button was pressed.
Client handles app signal(virtually press designed button).
I know most of the classes I will use, however I am clueless about PC client handling signals from the phone(step 4). If you could tell me which class/classes should I use for those "virtual presses" it would be great. Thank you.
The app running on the PC will be a server rather than a client, if the phone connects to it.
It will not be easy to send keyboard events from a Java application (though that might be possible), doing a simple server in C or C++ is probably easier (I assume your PC is windows based). Win32 API has a SendInput method to generate a keyboard event (example: http://batchloaf.wordpress.com/2012/04/17/simulating-a-keystroke-in-win32-c-or-c-using-sendinput/).
The communication between the android app and the PC can rely on a simple TCP socket (UDP is also a valid option but if you begin in network programming TCP is probably easier to handle and more widely used). On the C/C++ server, look at the functions socket, bind, listen, accept and then recv. On the android app, Socket and DataOutputStream classes should do the job.

How can two instances of an application communicate in Java?

I am developing a new Java Desktop app. Something like a media player. I want to load most of the resources in the background when the computer starts up. But the users can turn this option off form within the app or using some other utility. So, what I want to do is if a ban instance of the app is already running and the user starts the app again then I can communicate with the already running instance so that it can launch a new window?
The most known way to do that is to open a ServerSocket when first application starts on a well known port.
If ServerSocket fails to load, it's probably because an instance is already running.
In such a case, you can open a Socket and start to communicate your orders between both instances.
But you can also use far more sophisticated solutions, like Jini or JGroups.
Write the app so it has a server part
When it starts up, try to communicate to the server (if it is already running), and if that works, then the server should open a new window, and the client should die
This should give you an overview:
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
You could use ports.

Categories