└── Gopro
├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── proguard-project.txt
├── project.properties
├── res
├── drawable
│ └── ic_launcher.png
├── layout
│ ├── main.xml
│ └── settings.xml
└── values
│ └── strings.xml
└── src
└── com
└── mooh
└── gopro
└── GoproActivity.java
/Gopro/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Gopro/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Gopro
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Gopro/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Sun Oct 14 15:54:51 CEST 2012
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.compliance=1.5
5 | org.eclipse.jdt.core.compiler.source=1.5
6 |
--------------------------------------------------------------------------------
/Gopro/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Gopro/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/Gopro/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-8
15 |
--------------------------------------------------------------------------------
/Gopro/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/moohtwo/Android-GoPro-Streaming/293cc1d08484acf3e770d98da8bde9e295db90e3/Gopro/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/Gopro/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
18 |
19 |
27 |
28 |
35 |
36 |
37 |
38 |
44 |
45 |
48 |
49 |
54 |
55 |
61 |
62 |
63 |
64 |
73 |
74 |
--------------------------------------------------------------------------------
/Gopro/res/layout/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
16 |
26 |
27 |
--------------------------------------------------------------------------------
/Gopro/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello World, GoproActivity!
5 | Gopro
6 | SSID
7 | Password
8 | GoPro WIFI settings
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Gopro/src/com/mooh/gopro/GoproActivity.java:
--------------------------------------------------------------------------------
1 | package com.mooh.gopro;
2 |
3 | /*
4 | *
5 | Turn ON the Camera:
6 | http://10.5.5.9/bacpac/PW?t=WIFIPASSWORD&p=%01
7 |
8 | Wait about 15 Seconds for the Camera to turn on and the web interface to start.
9 | Then turn streaming ON:
10 | http://10.5.5.9/camera/PV?t=WIFIPASSWORD&p=%02
11 |
12 | Use VLC or whatever to watch the stream..
13 | http://10.5.5.9:8080/live/amba.m3u8
14 |
15 | If you want to turn the streaming OFF:
16 | http://10.5.5.9/camera/PV?t=WIFIPASSWORD&p=%01
17 |
18 | If you want to turn the Camera off:
19 | http://10.5.5.9/camera/PW?t=WIFIPASSWORD&p=%00
20 | *
21 | */
22 | import java.io.BufferedInputStream;
23 | import java.io.IOException;
24 | import java.io.InputStream;
25 | import java.net.HttpURLConnection;
26 | import java.net.MalformedURLException;
27 | import java.net.URL;
28 | import java.util.List;
29 |
30 | import android.app.Activity;
31 | import android.app.AlertDialog;
32 | import android.content.BroadcastReceiver;
33 | import android.content.Context;
34 | import android.content.DialogInterface;
35 | import android.content.Intent;
36 | import android.content.IntentFilter;
37 | import android.content.SharedPreferences;
38 | import android.net.NetworkInfo;
39 | import android.net.NetworkInfo.State;
40 | import android.net.wifi.WifiConfiguration;
41 | import android.net.wifi.WifiInfo;
42 | import android.net.wifi.WifiManager;
43 | import android.os.Bundle;
44 | import android.util.Log;
45 | import android.view.LayoutInflater;
46 | import android.view.Menu;
47 | import android.view.MenuItem;
48 | import android.view.View;
49 | import android.view.View.OnClickListener;
50 | import android.view.ViewGroup;
51 | import android.widget.Button;
52 | import android.widget.EditText;
53 | import android.widget.TextView;
54 | import android.widget.ToggleButton;
55 |
56 | public class GoproActivity extends Activity {
57 |
58 | private static final String TAG = "gopro";
59 | public static final String PREFS_NAME = "MyPrefsFile";
60 |
61 | WifiManager wifiManager;
62 | WifiReceiver wifiReceiver;
63 | Button wifiButton;
64 | TextView log;
65 |
66 |
67 | String wifiSSID;
68 | String wifiPass;
69 |
70 | @Override
71 | public void onCreate(Bundle savedInstanceState) {
72 | super.onCreate(savedInstanceState);
73 | setContentView(R.layout.main);
74 | log = (TextView) findViewById(R.id.log);
75 |
76 | wifiButton = (Button) findViewById(R.id.wifi);
77 | wifiButton.setOnClickListener(new OnClickListener() {
78 | public void onClick(View arg0) {
79 | refreshWifi();
80 | }
81 | });
82 |
83 | // Restore preferences
84 | SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
85 | wifiSSID = settings.getString("wifiSSID", "");
86 | wifiPass = settings.getString("wifiPass", "");
87 |
88 | if (wifiSSID.equals("") || wifiPass.equals("")) {
89 | displaySettingPopup();
90 | }
91 |
92 | wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
93 | WifiInfo wifiInfo = wifiManager.getConnectionInfo();
94 | log.setText(wifiInfo.getSSID());
95 | wifiReceiver = new WifiReceiver();
96 | registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
97 |
98 | if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED) {
99 | log.setText("Disconnected");
100 | wifiManager.setWifiEnabled(true);
101 | }
102 |
103 | WifiConfiguration conf = new WifiConfiguration();
104 | conf.SSID = "\"" + wifiSSID + "\"";
105 | conf.preSharedKey = "\"" + wifiPass + "\"";
106 | wifiManager.addNetwork(conf);
107 |
108 | refreshWifi();
109 |
110 | }
111 |
112 | private void displaySettingPopup() {
113 | LayoutInflater inflater = getLayoutInflater();
114 | View dialoglayout = inflater.inflate(R.layout.settings,
115 | (ViewGroup) getCurrentFocus());
116 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
117 | builder.setView(dialoglayout);
118 |
119 | builder.setTitle(R.string.settings);
120 | final EditText ssidIN = (EditText) dialoglayout
121 | .findViewById(R.id.ssidIN);
122 | final EditText pwIN = (EditText) dialoglayout.findViewById(R.id.pwIN);
123 |
124 | final SharedPreferences preferences = getSharedPreferences(PREFS_NAME,
125 | 0);
126 | ssidIN.setText(preferences.getString("wifiSSID", "SSID"));
127 | pwIN.setText(preferences.getString("wifiPass", "password"));
128 |
129 | builder.setPositiveButton("Save",
130 | new DialogInterface.OnClickListener() {
131 | public void onClick(DialogInterface dialog, int id) {
132 |
133 | SharedPreferences.Editor editor = preferences.edit();
134 | editor.putString("wifiSSID", ssidIN.getText()
135 | .toString());
136 | wifiSSID = ssidIN.getText().toString();
137 | editor.putString("wifiPass", pwIN.getText().toString());
138 | wifiPass = pwIN.getText().toString();
139 |
140 | // commit the edits
141 | editor.commit();
142 |
143 | }
144 | });
145 |
146 | AlertDialog alert = builder.create();
147 | alert.show();
148 | }
149 |
150 | public boolean onCreateOptionsMenu(Menu menu) {
151 | menu.add(0, 0, 0, "Settings");
152 | return super.onCreateOptionsMenu(menu);
153 | }
154 |
155 | public boolean onMenuItemSelected(int featureId, MenuItem item) {
156 | displaySettingPopup();
157 | return super.onMenuItemSelected(featureId, item);
158 | }
159 |
160 | protected void refreshWifi() {
161 | if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED) {
162 | wifiManager.setWifiEnabled(true);
163 | }
164 | WifiInfo wifiInfo = wifiManager.getConnectionInfo();
165 |
166 | if (wifiInfo.getSSID() == null || !wifiInfo.getSSID().equals(wifiSSID)) {
167 |
168 | List list = wifiManager.getConfiguredNetworks();
169 | for (WifiConfiguration i : list) {
170 | if (i.SSID != null && i.SSID.equals("\"" + wifiSSID + "\"")) {
171 | wifiManager.disconnect();
172 | wifiManager.enableNetwork(i.networkId, true);
173 | wifiManager.reconnect();
174 |
175 | break;
176 | }
177 | }
178 | }
179 |
180 | }
181 |
182 | public void onToggleClicked(View view) {
183 | boolean on = ((ToggleButton) view).isChecked();
184 | URL url;
185 | try {
186 | if (on) {
187 | // Enable streaming
188 | url = new URL("http://10.5.5.9/camera/PV?t=" + wifiPass
189 | + "&p=%02");
190 |
191 | } else {
192 | // Disable streaming
193 | url = new URL("http://10.5.5.9/camera/PV?t=" + wifiPass
194 | + "&p=%01");
195 | }
196 |
197 | HttpURLConnection urlConnection = (HttpURLConnection) url
198 | .openConnection();
199 | try {
200 | InputStream in = new BufferedInputStream(urlConnection.getInputStream());
201 | // readStream(in);
202 | } finally {
203 | urlConnection.disconnect();
204 | }
205 |
206 | } catch (MalformedURLException e) {
207 | // TODO Auto-generated catch block
208 | e.printStackTrace();
209 | } catch (IOException e) {
210 | // TODO Auto-generated catch block
211 | e.printStackTrace();
212 | }
213 | }
214 |
215 | protected void onPause() {
216 | unregisterReceiver(wifiReceiver);
217 | super.onPause();
218 | }
219 |
220 | protected void onResume() {
221 | registerReceiver(wifiReceiver, new IntentFilter(
222 | WifiManager.NETWORK_STATE_CHANGED_ACTION));
223 | super.onResume();
224 | }
225 |
226 | class WifiReceiver extends BroadcastReceiver {
227 | public void onReceive(Context c, Intent intent) {
228 | NetworkInfo wifiNetworkInfo = (NetworkInfo) intent
229 | .getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
230 | Log.v(TAG, "mWifiNetworkInfo: " + wifiNetworkInfo.toString());
231 |
232 | if (wifiNetworkInfo.getState() == State.CONNECTED) {
233 | log.setText("Connected to: "
234 | + wifiManager.getConnectionInfo().getSSID());
235 | if (wifiManager != null
236 | && wifiManager.getConnectionInfo() != null
237 | && wifiManager.getConnectionInfo().getSSID() != null
238 | && !wifiManager.getConnectionInfo().getSSID()
239 | .equals(wifiSSID)) {
240 | Log.v(TAG, wifiManager.getConnectionInfo().getSSID());
241 |
242 | refreshWifi();
243 | }
244 | } else if (wifiNetworkInfo.getState() == State.CONNECTING) {
245 | log.setText("Connecting...");
246 | } else if (wifiNetworkInfo.getState() == State.DISCONNECTING) {
247 | log.setText("Disconnecting...");
248 | } else if (wifiNetworkInfo.getState() == State.DISCONNECTED) {
249 | log.setText("Disconnected");
250 | }
251 |
252 | }
253 | }
254 | }
--------------------------------------------------------------------------------