Controlling GoPro with URL commands - android

I have a GoPro Hero3 Black Edition and after reading their user forums, I got these 2 url commands that can control the shutter button while the GoPro is acting as a hotspot.
Record/shoot Command
On http://10.5.5.9:80/bacpac/SH?t=WIFIPASSWORD&p=%01
Off http://10.5.5.9:80/bacpac/SH?t=WIFIPASSWORD&p=%00
I have tried using the URLs in my Nexus 7's Chrome Browser but I want to integrate these 2 commands in a button in my Android app when my Nexus 7 connects via wifi to the GoPro.
How do I do this? Thanks in advance.

It's not that tough. Create an activity class and a couple of buttons to fire the HTTP commands.
Keep in mind that these are network calls and have to be made from a separate background thread (not the main thread).
btnToggle.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Toggle the camera power
new OperateCamera().execute();
}
});
Create a new AsyncTask class:
class OperateCamera extends AsyncTask<String, Void, Boolean> {
protected Boolean doInBackground(String... urls) {
return triggerShutter();
}
// Method to trigger the shutter
boolean triggerShutter(){
try {
// Make network call
return true;
}
catch (Exception e) {
return false;
}
}
}

Just use the legacy URLConnection or some lib like OkHttp to access these urls and trigger the shutter. I'd recommend the second ;)

Related

How to call an Android app's method remotely?

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();
}
}
}
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
});

Fiddler capturing emulator's browser packets but not my app's

I've taken every step described here in Fiddler site for capturing my application (running in emulator) network packets. The strange thing is that I can decode http/https sent from browser but not https packets from my app. It's more interesting that requests get successful responses! Any idea what might be the problem?
I'm completely stocked and have no idea what should I have done which didn't.
First topic, that I've found on Xamarin forum was Why can't Fiddler detect traffic from Xamarin apps?. The answer is to set DefaultWebProxy:
public override void OnCreate()
{
// get IP from fiddler's internet icon at the top right, or via ipconfig for VirtualBox used by Genymotion
WebRequest.DefaultWebProxy = new WebProxy("192.168.56.1", 8888);
base.OnCreate();
...
}
I put it in MainActivity, but it didn't solve my problem.
Which helped me is Debugging HttpClient Calls with fiddler in PCL:
You will need to change your code to use a HttpClientHandler and a proxy
HttpClientHandler handler = new HttpClientHandler ()
{
Proxy = new WebProxy (new Uri("http://[Computer IP]:[Fiddler port number]")),
UseProxy = true
};
using (var client = new HttpClient(handler))
{
// Make your call in here
}
Looks simple enough only PCLs dont include the Web proxy class in its bundled System.Net dll for whatever reason so you will need to write your own by extending the System.Net.IWebProxy interface
like so
public class WebProxy : System.Net.IWebProxy
{
public System.Net.ICredentials Credentials
{
get;
set;
}
private readonly Uri _proxyUri;
public WebProxy(Uri proxyUri)
{
_proxyUri = proxyUri;
}
public Uri GetProxy(Uri destination)
{
return _proxyUri;
}
public bool IsBypassed(Uri host)
{
return false;
}
}
After all this stuff, I was able to capture requests from my Xamarin.Forms app on Android Emulator.

Best practice for closing websocket in android

I am using this library for connecting to a websocket server from android.
Specifically this part :
AsyncHttpClient.getDefaultInstance().websocket("ws://192.168.2.10:8000/temp" , "my-protocol", new WebSocketConnectCallback() {
#Override
public void onCompleted(Exception ex, WebSocket webSocket) {
if (ex != null) {
ex.printStackTrace();
return;
}
webSocket.send("a string");
webSocket.setStringCallback(new StringCallback() {
#Override
public void onStringAvailable(String s) {
Debug.Log( LOGTAG ,"I got a string: " + s);
}
});
webSocket.close(); // issue here
}
});
I would like to close the socket when I click a button. Now everytime I want to send a message to the socket I open it and close it.
I would like to open it once and keep it alive and close it when I click a close button. My idea was to pass a variable to the WebSocketConnectCallback and make a static variable and based on this variable close the socket.
I would like to know what is the best practice in a situation like this.
Use the Application class (http://developer.android.com/reference/android/app/Application.html):
Inherid your own class for Application and here you can track the socket, open it, close it as you need.
See a tutorial (first google match, maybe there is a better one): http://www.intertech.com/Blog/androids-application-class/
So basically extend Application and add your class in the manifest file as application class.
Your may add a timer that might close the socket after several time while not used.

SDK Android : How to open Shutdown/Reboot dialog for the device

I'm new here.
I have a problem, i try to shutdown a 4.2.2 android device (not root).
I know that ACTION_SHUTDOWN not works with unroot device.
So i want to open the existing shutdown/reboot/airplane dialog, the same we get when we maintain the on/off button. Then the user just have to click shutdown button.
I try to create by this way, without result...
Intent intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS); // or others settings
startActivity(intent);
Thanks,
The is no public sdk access to open the power button menu programatically.
This link has all the approches Here.Simulating power button press to display switch off dialog box
InputManager.getInstance().injectInputEvent(new InputEvent(KeyEvent.KEYCODE_POWER, keyCode), sync);
'sync' becomes either of these:
InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH
InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT
and you need
import android.hardware.input.InputManager;
This is untested, but puts you in the right direction, also bare in mind, functionality like this is NOT recommend.
failing that:
public static void simulateKey(final int KeyCode) {
new Thread() {
#Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyCode);
} catch (Exception e) {
Log.e("Exception when sendKeyDownUpSync", e.toString());
}
}
}.start();
}
and simply call it like
simulateKey(KeyEvent.KEYCODE_POWER);

Android Browser can not support play list with HTML5 Audio in background mode

I want to make Radio Web App Android-browser-based.
The key function for my Web App is continuously playing music-list
(mp3 files) ...
JavaScript Code is simple ...
And it works well in PC Browser, iOS safari, and Android Dolphin
Browser (3rd party browser)...
var audioPlayer = new Audio();
audioPlayer.addEventListener('ended', nextSong, false);
function nextSong() {
audioPlayer.src = nextMusic_src;
}
But. in Android Default Browser,
when android is in background mode (Home Screen mode & LCD-off Sleep
mode),
Android Browser's onPause() prevent "ended" event & execution of
nextSong().
So, my web app can play only one music.... and does not work any
more.....
Android Browser's onPause() source code is like this ...
BrowserActivity.java
public class BrowserActivity extends Activity
{
private Controller mController;
// ...
#Override
protected void onPause() {
if (mController != null) {
mController.onPause(); // <<==== here
}
super.onPause();
}
}
Controller.java
public class Controller implements WebViewController, UiController {
protected void onPause() {
// ...
mActivityPaused = true;
// ...
mUi.onPause();
mNetworkHandler.onPause(); // <<==== here
WebView.disablePlatformNotifications(); // <<====here
}
}
NetworkStateHandler.java
public class NetworkStateHandler {
// ...
void onPause() {
// unregister network state listener
mActivity.unregisterReceiver(mNetworkStateIntentReceiver); // <<==== here
}
}
Is there any browser policy for preventing event in background
mode....?
If not, how can I notice this report to the Google developer for
requesting background music play with web app...?
I consider not WebView based web-app (Hybrid) but only browser-based
web-app...
thank you...
Nohyun Kwak
Droid's ended event doesn't fire consistently. It's fixed in ICS, I hear. But Gingerbread and prior have the issue.
Instead of listening for .ended, can you listen for .timeupdate and in that handler, see if the time is the end of the song? That may solve your issue.

Categories

Resources