OPC(Olympus Air)用撮影アプリ。
Révision | 716522ca6a33342bbf3885e7e3631480392e94fa (tree) |
---|---|
l'heure | 2021-01-21 23:18:13 |
Auteur | MRSa <mrsa@myad...> |
Commiter | MRSa |
Wifiの接続についてちょっと改善。
@@ -116,6 +116,7 @@ public class MainActivity extends AppCompatActivity implements IChangeScene, IS | ||
116 | 116 | setupActionListener(); |
117 | 117 | |
118 | 118 | wifiConnection = new WifiConnection(this, this); |
119 | + wifiConnection.requestNetwork(); | |
119 | 120 | } |
120 | 121 | catch (Exception e) |
121 | 122 | { |
@@ -61,7 +61,7 @@ class WifiConnection(private val context: AppCompatActivity, private val callbac | ||
61 | 61 | |
62 | 62 | override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities) |
63 | 63 | { |
64 | - context.runOnUiThread { Log.d(TAG, "Network capabilities changed") } | |
64 | + Log.d(TAG, "Network capabilities changed") | |
65 | 65 | } |
66 | 66 | |
67 | 67 | override fun onLost(network: Network) |
@@ -182,7 +182,6 @@ class WifiConnection(private val context: AppCompatActivity, private val callbac | ||
182 | 182 | * Wifi接続状態の監視 |
183 | 183 | * (接続の実処理は onReceiveBroadcastOfConnection() で実施) |
184 | 184 | */ |
185 | - @Suppress("DEPRECATION") | |
186 | 185 | fun startWatchWifiStatus() |
187 | 186 | { |
188 | 187 | Log.v(TAG, "startWatchWifiStatus()") |
@@ -215,23 +214,49 @@ class WifiConnection(private val context: AppCompatActivity, private val callbac | ||
215 | 214 | |
216 | 215 | private fun requestHighBandwidthNetwork() |
217 | 216 | { |
218 | - // Before requesting a high-bandwidth network, ensure prior requests are invalidated. | |
219 | - unregisterNetworkCallback() | |
220 | - Log.d(TAG, "requestHighBandwidthNetwork(): Requesting high-bandwidth network") | |
221 | - | |
222 | - // Requesting an unmetered network may prevent you from connecting to the cellular | |
223 | - // network on the user's watch or phone; however, unless you explicitly ask for permission | |
224 | - // to a access the user's cellular network, you should request an unmetered network. | |
225 | - val request = NetworkRequest.Builder() | |
226 | - .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) | |
227 | - .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) | |
228 | - .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) | |
229 | - .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) | |
230 | - .build() | |
231 | - | |
232 | - // requires android.permission.CHANGE_NETWORK_STATE | |
233 | - connectivityManager.requestNetwork(request, networkCallback) | |
234 | - networkConnectionTimeoutHandler.sendMessageDelayed(networkConnectionTimeoutHandler.obtainMessage(MESSAGE_CONNECTIVITY_TIMEOUT), NETWORK_CONNECTIVITY_TIMEOUT_MS) | |
217 | + try | |
218 | + { | |
219 | + val bandwidth: Int = connectivityManager.activeNetwork?.let { activeNetwork -> | |
220 | + connectivityManager.getNetworkCapabilities(activeNetwork)?.linkDownstreamBandwidthKbps | |
221 | + } ?: -1 | |
222 | + Log.v(TAG, " requestHighBandwidthNetwork() (Bandwidth: $bandwidth)") | |
223 | + when | |
224 | + { | |
225 | + bandwidth < 0 -> { | |
226 | + // No active network | |
227 | + } | |
228 | + bandwidth in (0 until MIN_NETWORK_BANDWIDTH_KBPS) -> { | |
229 | + // Request a high-bandwidth network | |
230 | + } | |
231 | + else -> { | |
232 | + // すでにつながっているので、何もしない。 | |
233 | + Log.d(TAG, " already connected with high-bandwidth network") | |
234 | + return | |
235 | + } | |
236 | + } | |
237 | + | |
238 | + // Before requesting a high-bandwidth network, ensure prior requests are invalidated. | |
239 | + unregisterNetworkCallback() | |
240 | + Log.d(TAG, "requestHighBandwidthNetwork(): Requesting high-bandwidth network") | |
241 | + | |
242 | + // Requesting an unmetered network may prevent you from connecting to the cellular | |
243 | + // network on the user's watch or phone; however, unless you explicitly ask for permission | |
244 | + // to a access the user's cellular network, you should request an unmetered network. | |
245 | + val request = NetworkRequest.Builder() | |
246 | + .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) | |
247 | + .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) | |
248 | + .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) | |
249 | + .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) | |
250 | + .build() | |
251 | + | |
252 | + // requires android.permission.CHANGE_NETWORK_STATE | |
253 | + connectivityManager.requestNetwork(request, networkCallback) | |
254 | + networkConnectionTimeoutHandler.sendMessageDelayed(networkConnectionTimeoutHandler.obtainMessage(MESSAGE_CONNECTIVITY_TIMEOUT), NETWORK_CONNECTIVITY_TIMEOUT_MS) | |
255 | + } | |
256 | + catch (e : Exception) | |
257 | + { | |
258 | + e.printStackTrace() | |
259 | + } | |
235 | 260 | } |
236 | 261 | |
237 | 262 | companion object |
@@ -42,7 +42,7 @@ | ||
42 | 42 | <string name="shoot_camera">撮影!</string> |
43 | 43 | <string name="shoot_camera_failure">失敗です…</string> |
44 | 44 | <string name="video_recording">●REC</string> |
45 | - <string name="capturing">CAPTURE</string> | |
45 | + <string name="capturing">INTERVAL</string> | |
46 | 46 | <string name="video_failure">失敗です…</string> |
47 | 47 | <string name="message_none">---</string> |
48 | 48 |
@@ -41,7 +41,7 @@ | ||
41 | 41 | <string name="shoot_camera">Capture!</string> |
42 | 42 | <string name="shoot_camera_failure">FAILED!</string> |
43 | 43 | <string name="video_recording">●REC</string> |
44 | - <string name="capturing">CAPTURE</string> | |
44 | + <string name="capturing">INTERVAL</string> | |
45 | 45 | <string name="video_failure">FAILED!</string> |
46 | 46 | <string name="message_none">---</string> |
47 | 47 |