How to call an Android app's method remotely?

262 Views Asked by At

I'm working on a project that improves Automation Test for Android's App. What I want to do is very "easy": I have this very simple SIP Client with a basic UI and developed just reading the API guides on the android developer website (https://developer.android.com/guide/topics/connectivity/sip.html) that receives and makes SIP calls.

I need to control remotely this app from my PC, connected at the same local network or the same wifi, by sending commands or similar (without interact with the phone) to the app itslef running normally on my phone.For a specific example I posted the method initiateCall() that calls sipAddress(in the app, sipAddress is taken from a Text Box), what I want to do is:

  • Starting the app on my phone
  • calling the method initiateCall() from my pc giving a sipAddress as a parameter (I must not use the UI from the app running, that's why I need to give the sipAddress)
  • check if an outgoing call starts from the app running on my phone

I thought that the solution must be something about web-services,but I don't have any better ideas and i don't know how to start and where to start solving this problem,that's why i need you help.

public void initiateCall() {
    try {
        SipAudioCall.Listener listener = new SipAudioCall.Listener() {
         // set up the listener for outgoing calls
            @Override
            public void onCallEstablished(SipAudioCall call) {
                call.startAudio();
                call.setSpeakerMode(true);
                updateStatus(call, 2);
            }

            @Override
            public void onCallEnded(SipAudioCall call) {
                updateStatus("Call End");
            }
        };

        call = manager.makeAudioCall(me.getUriString(), sipAddress,
                listener, 30);

    } catch (Exception e) {
        Log.i("WalkieTalkieActivity/InitiateCall",
                "Error when trying to close manager.", e);
        if (me != null) {
            try {
                manager.close(me.getUriString());
            } catch (Exception ee) {
                Log.i("WalkieTalkieActivity/InitiateCall",
                        "Error when trying to close manager.", ee);
                ee.printStackTrace();
            }
        }
        if (call != null) {
            call.close();
        }
    }
}
1

There are 1 best solutions below

9
On

You could do it REST API style. You would need to set up a minimalistic webserver.

If you access for example the url phoneip/ctrl/makecall?number=yournumber a serverside method us called if set up correctly. Then you can call you method and use the GET or POST variables as arguments.

You would have to look into Java Webserver Libraries/Frameworks. You can pick a lightweight one for that purpose. For example this one. You could then also add security features (authentification to protect it) quite easily.

Example with sparkjava

import static spark.Spark.*;

....

get("/ctrl/makecall", (request, response) -> {
      String phonenum =  request.queryParams("number"); //may not be accurate; you have to determine the GET variable called "number" in that case; you can rename it; see docs!!!
      //call your method with proper arguments
});