TetheringManager
public
class
TetheringManager
extends Object
java.lang.Object | |
↳ | android.net.TetheringManager |
This class provides the APIs to control the tethering service.
The primary responsibilities of this class are to provide the APIs for applications to start tethering, stop tethering, query configuration and query status.
Summary
Nested classes | |
---|---|
interface |
TetheringManager.StartTetheringCallback
Callback for use with |
interface |
TetheringManager.StopTetheringCallback
Callback for use with |
interface |
TetheringManager.TetheringEventCallback
Callback for use with |
class |
TetheringManager.TetheringRequest
Use with |
Constants | |
---|---|
int |
CONNECTIVITY_SCOPE_GLOBAL
Indicates that this tethering connection will provide connectivity beyond this device (e.g., global Internet access). |
int |
TETHERING_WIFI
Wifi tethering type. |
int |
TETHER_ERROR_DHCPSERVER_ERROR
|
int |
TETHER_ERROR_DISABLE_FORWARDING_ERROR
|
int |
TETHER_ERROR_DUPLICATE_REQUEST
|
int |
TETHER_ERROR_ENABLE_FORWARDING_ERROR
|
int |
TETHER_ERROR_ENTITLEMENT_UNKNOWN
|
int |
TETHER_ERROR_IFACE_CFG_ERROR
|
int |
TETHER_ERROR_INTERNAL_ERROR
|
int |
TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION
|
int |
TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION
|
int |
TETHER_ERROR_NO_ERROR
|
int |
TETHER_ERROR_PROVISIONING_FAILED
|
int |
TETHER_ERROR_SERVICE_UNAVAIL
|
int |
TETHER_ERROR_TETHER_IFACE_ERROR
|
int |
TETHER_ERROR_UNAVAIL_IFACE
|
int |
TETHER_ERROR_UNKNOWN_IFACE
|
int |
TETHER_ERROR_UNKNOWN_REQUEST
|
int |
TETHER_ERROR_UNKNOWN_TYPE
|
int |
TETHER_ERROR_UNSUPPORTED
|
int |
TETHER_ERROR_UNTETHER_IFACE_ERROR
|
Public methods | |
---|---|
void
|
registerTetheringEventCallback(Executor executor, TetheringManager.TetheringEventCallback callback)
Start listening to tethering change events. |
void
|
startTethering(TetheringManager.TetheringRequest request, Executor executor, TetheringManager.StartTetheringCallback callback)
Starts tethering and runs tether provisioning for the given type if needed. |
void
|
stopTethering(TetheringManager.TetheringRequest request, Executor executor, TetheringManager.StopTetheringCallback callback)
Stops tethering for the given request. |
void
|
unregisterTetheringEventCallback(TetheringManager.TetheringEventCallback callback)
Remove tethering event callback previously registered with
|
Inherited methods | |
---|---|
Constants
CONNECTIVITY_SCOPE_GLOBAL
public static final int CONNECTIVITY_SCOPE_GLOBAL
Indicates that this tethering connection will provide connectivity beyond this device (e.g., global Internet access).
Constant Value: 1 (0x00000001)
TETHERING_WIFI
public static final int TETHERING_WIFI
Wifi tethering type.
See also:
Constant Value: 0 (0x00000000)
TETHER_ERROR_DHCPSERVER_ERROR
public static final int TETHER_ERROR_DHCPSERVER_ERROR
Constant Value: 12 (0x0000000c)
TETHER_ERROR_DISABLE_FORWARDING_ERROR
public static final int TETHER_ERROR_DISABLE_FORWARDING_ERROR
Constant Value: 9 (0x00000009)
TETHER_ERROR_DUPLICATE_REQUEST
public static final int TETHER_ERROR_DUPLICATE_REQUEST
Constant Value: 18 (0x00000012)
TETHER_ERROR_ENABLE_FORWARDING_ERROR
public static final int TETHER_ERROR_ENABLE_FORWARDING_ERROR
Constant Value: 8 (0x00000008)
TETHER_ERROR_ENTITLEMENT_UNKNOWN
public static final int TETHER_ERROR_ENTITLEMENT_UNKNOWN
Constant Value: 13 (0x0000000d)
TETHER_ERROR_IFACE_CFG_ERROR
public static final int TETHER_ERROR_IFACE_CFG_ERROR
Constant Value: 10 (0x0000000a)
TETHER_ERROR_INTERNAL_ERROR
public static final int TETHER_ERROR_INTERNAL_ERROR
Constant Value: 5 (0x00000005)
TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION
public static final int TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION
Constant Value: 15 (0x0000000f)
TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION
public static final int TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION
Constant Value: 14 (0x0000000e)
TETHER_ERROR_NO_ERROR
public static final int TETHER_ERROR_NO_ERROR
Constant Value: 0 (0x00000000)
TETHER_ERROR_PROVISIONING_FAILED
public static final int TETHER_ERROR_PROVISIONING_FAILED
Constant Value: 11 (0x0000000b)
TETHER_ERROR_SERVICE_UNAVAIL
public static final int TETHER_ERROR_SERVICE_UNAVAIL
Constant Value: 2 (0x00000002)
TETHER_ERROR_TETHER_IFACE_ERROR
public static final int TETHER_ERROR_TETHER_IFACE_ERROR
Constant Value: 6 (0x00000006)
TETHER_ERROR_UNAVAIL_IFACE
public static final int TETHER_ERROR_UNAVAIL_IFACE
Constant Value: 4 (0x00000004)
TETHER_ERROR_UNKNOWN_IFACE
public static final int TETHER_ERROR_UNKNOWN_IFACE
Constant Value: 1 (0x00000001)
TETHER_ERROR_UNKNOWN_REQUEST
public static final int TETHER_ERROR_UNKNOWN_REQUEST
Constant Value: 17 (0x00000011)
TETHER_ERROR_UNKNOWN_TYPE
public static final int TETHER_ERROR_UNKNOWN_TYPE
Constant Value: 16 (0x00000010)
TETHER_ERROR_UNSUPPORTED
public static final int TETHER_ERROR_UNSUPPORTED
Constant Value: 3 (0x00000003)
TETHER_ERROR_UNTETHER_IFACE_ERROR
public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR
Constant Value: 7 (0x00000007)
Public methods
registerTetheringEventCallback
public void registerTetheringEventCallback (Executor executor, TetheringManager.TetheringEventCallback callback)
Start listening to tethering change events. Any new added callback will receive the last
tethering status right away. If callback is registered,
ERROR(TetheringEventCallback.onUpstreamChanged/android.net.TetheringManager.TetheringEventCallback#onUpstreamChanged TetheringEventCallback.onUpstreamChanged)
will immediately be called. If tethering
has no upstream or disabled, the argument of callback will be null. The same callback object
cannot be registered twice.
Requires Manifest.permission.ACCESS_NETWORK_STATE
Parameters | |
---|---|
executor |
Executor : the executor on which callback will be invoked.
This value cannot be null . |
callback |
TetheringManager.TetheringEventCallback : the callback to be called when tethering has change events.
This value cannot be null . |
startTethering
public void startTethering (TetheringManager.TetheringRequest request, Executor executor, TetheringManager.StartTetheringCallback callback)
Starts tethering and runs tether provisioning for the given type if needed. If provisioning fails, stopTethering will be called automatically.
Parameters | |
---|---|
request |
TetheringManager.TetheringRequest : a TetheringRequest which can specify the preferred configuration.
This value cannot be null . |
executor |
Executor : Executor to specify the thread upon which the callback of
TetheringRequest will be invoked.
This value cannot be null . |
callback |
TetheringManager.StartTetheringCallback : A callback that will be called to indicate the success status of the
tethering start request.
This value cannot be null . |
stopTethering
public void stopTethering (TetheringManager.TetheringRequest request, Executor executor, TetheringManager.StopTetheringCallback callback)
Stops tethering for the given request. Operation will fail with
TETHER_ERROR_UNKNOWN_REQUEST
if there is no request that matches it.
Parameters | |
---|---|
request |
TetheringManager.TetheringRequest : This value cannot be null . |
executor |
Executor : This value cannot be null . |
callback |
TetheringManager.StopTetheringCallback : This value cannot be null . |
unregisterTetheringEventCallback
public void unregisterTetheringEventCallback (TetheringManager.TetheringEventCallback callback)
Remove tethering event callback previously registered with
registerTetheringEventCallback(Executor, TetheringEventCallback)
.
Requires ERROR(/android.Manifest.permission#TETHER_PRIVILEGED)
or Manifest.permission.ACCESS_NETWORK_STATE
Parameters | |
---|---|
callback |
TetheringManager.TetheringEventCallback : previously registered callback.
This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-01-23 UTC.