Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QtNetwork.java
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android.network;
5
6import android.content.BroadcastReceiver;
7import android.content.Context;
8import android.content.Intent;
9import android.content.IntentFilter;
10import android.net.ConnectivityManager;
11import android.net.Proxy;
12import android.net.ProxyInfo;
13
14public class QtNetwork
15{
16 private static final String LOG_TAG = "QtNetwork";
17 private static ProxyReceiver m_proxyReceiver = null;
18 private static final Object m_lock = new Object();
19 private static ProxyInfo m_proxyInfo = null;
20
21 private static class ProxyReceiver extends BroadcastReceiver
22 {
23 @Override
24 public void onReceive(Context context, Intent intent)
25 {
26 m_proxyInfo = null;
27 }
28 }
29
30 private QtNetwork() {}
31
32 public static void registerReceiver(final Context context)
33 {
34 synchronized (m_lock) {
35 if (m_proxyReceiver == null) {
36 m_proxyReceiver = new ProxyReceiver();
37 IntentFilter intentFilter = new IntentFilter(Proxy.PROXY_CHANGE_ACTION);
38 context.registerReceiver(m_proxyReceiver, intentFilter);
39 }
40 }
41 }
42
43 public static void unregisterReceiver(final Context context)
44 {
45 synchronized (m_lock) {
46 if (m_proxyReceiver == null)
47 return;
48
49 context.unregisterReceiver(m_proxyReceiver);
50 }
51 }
52
53 public static ConnectivityManager getConnectivityManager(final Context context)
54 {
55 return (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
56 }
57
58 public static ProxyInfo getProxyInfo(final Context context)
59 {
60 if (m_proxyInfo == null)
61 m_proxyInfo = (ProxyInfo)getConnectivityManager(context).getDefaultProxy();
62 return m_proxyInfo;
63 }
64}
Definition main.cpp:8
static ConnectivityManager getConnectivityManager(final Context context)
static ProxyInfo getProxyInfo(final Context context)
static void registerReceiver(final Context context)
static void unregisterReceiver(final Context context)
static void * context