public class Connectivity
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Connectivity.DeviceListener
DeviceListeners are interested in all events that could happen with Connectivity.
|
static class |
Connectivity.DeviceListenerAdapter
Convenience class for implementing a DeviceListener without having to implement all methods.
|
static class |
Connectivity.SynchronousOrderedBroadcastResult
A simple data-struct to pass the results of a synchronous ordered broadcast around
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTION_DEVICE_ADDED |
static java.lang.String |
ACTION_DEVICE_CHANGED |
static java.lang.String |
ACTION_DEVICE_CONNECTED |
static java.lang.String |
ACTION_DEVICE_DISCONNECTED |
static java.lang.String |
ACTION_DEVICE_REMOVED |
static java.lang.String |
ACTION_ORDERED_BROADCAST_RESULT |
static java.lang.String |
EXTRA_BROADCAST_ID |
static java.lang.String |
EXTRA_BROADCAST_RESULT_CODE |
static java.lang.String |
EXTRA_BROADCAST_RESULT_DATA |
static java.lang.String |
EXTRA_BROADCAST_RESULT_EXTRAS |
static java.lang.String |
EXTRA_DEVICE_ID |
static java.lang.String |
EXTRA_SENDING_PACKAGE |
static java.lang.String |
EXTRA_VERIFY_DATA |
static java.lang.String |
EXTRA_VERIFY_SIGNATURE |
Modifier and Type | Method and Description |
---|---|
void |
addDeviceListener(Connectivity.DeviceListener listener)
Adds a DeviceListener which will be notified when Connectivity events happen.
|
static Connectivity |
get(android.content.Context context)
Returns the global Connectivity object associated with your application.
|
Device |
getDevice()
Convenience method for obtaining a remote device.
|
Device |
getDevice(long id)
Returns a device with the specified id.
|
java.util.List<Device> |
getDevices()
Returns a list of all available remote devices that are linked to this device.
|
Device |
getSendingDevice(android.content.Intent intent)
Determines the remote device that sent the given intent.
|
static long |
getSendingDeviceId(android.content.Intent intent)
Extracts the device id from an intent.
|
static java.lang.String |
getSendingPackage(android.content.Intent intent)
Determines the remote package (app) that sent the intent.
|
boolean |
isAvailable()
Determines if Connectivity is available on this device.
|
boolean |
isConnected()
Determines if any remote devices are currently connected.
|
boolean |
isConnected(Device device)
Determines if the specified device is currently connected.
|
boolean |
isLinked()
Determines if any remote devices are linked.
|
void |
removeDeviceListener(Connectivity.DeviceListener listener)
Removes a DeviceListener.
|
boolean |
sendBroadcast(Device device,
android.content.Intent intent)
Sends a broadcast to the specified remote device.
|
boolean |
sendBroadcast(android.content.Intent intent)
Sends a broadcast to all connected remote devices.
|
boolean |
sendOrderedBroadcast(Device device,
android.content.Intent intent)
Sends an ordered broadcast to the specified remote device.
|
boolean |
sendOrderedBroadcast(Device device,
android.content.Intent intent,
android.content.BroadcastReceiver resultReceiver)
Sends an ordered broadcast to the specified remote device.
|
boolean |
sendOrderedBroadcast(Device device,
android.content.Intent intent,
android.content.BroadcastReceiver resultReceiver,
int initialCode,
java.lang.String initialData,
android.os.Bundle initialExtras)
Sends an ordered broadcast to the specified remote device.
|
Connectivity.SynchronousOrderedBroadcastResult |
sendSynchronousOrderedBroadcast(Device device,
android.content.Intent intent)
Synchronously send an ordered broadcast message to a remote device.
|
boolean |
verify(android.content.Intent intent)
Determines if the given intent is a valid intent that came from the Connectivity framework.
|
boolean |
verify(android.content.Intent intent,
java.lang.String _package)
Determines if the given intent is a valid intent that came from the Connectivity framework
and that it originated from the specified package.
|
public static final java.lang.String ACTION_DEVICE_ADDED
public static final java.lang.String ACTION_DEVICE_CHANGED
public static final java.lang.String ACTION_DEVICE_REMOVED
public static final java.lang.String ACTION_DEVICE_CONNECTED
public static final java.lang.String ACTION_DEVICE_DISCONNECTED
public static final java.lang.String ACTION_ORDERED_BROADCAST_RESULT
public static final java.lang.String EXTRA_DEVICE_ID
public static final java.lang.String EXTRA_SENDING_PACKAGE
public static final java.lang.String EXTRA_VERIFY_DATA
public static final java.lang.String EXTRA_VERIFY_SIGNATURE
public static final java.lang.String EXTRA_BROADCAST_ID
public static final java.lang.String EXTRA_BROADCAST_RESULT_CODE
public static final java.lang.String EXTRA_BROADCAST_RESULT_DATA
public static final java.lang.String EXTRA_BROADCAST_RESULT_EXTRAS
public static Connectivity get(android.content.Context context)
context
- a Contextpublic void addDeviceListener(Connectivity.DeviceListener listener)
listener
- the DeviceListener to addpublic void removeDeviceListener(Connectivity.DeviceListener listener)
listener
- the DeviceListener to removepublic boolean isAvailable()
public java.util.List<Device> getDevices()
public Device getDevice(long id)
id
- the id of a Devicepublic Device getDevice()
public boolean isLinked()
public boolean isConnected()
public boolean isConnected(Device device)
device
- a Devicepublic boolean sendBroadcast(android.content.Intent intent)
intent
- the Intent to send as a broadcastpublic boolean sendBroadcast(Device device, android.content.Intent intent)
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcastpublic Connectivity.SynchronousOrderedBroadcastResult sendSynchronousOrderedBroadcast(Device device, android.content.Intent intent) throws java.lang.InterruptedException
device
- the Device to send request tointent
- the Intent to send as a broadcastjava.lang.InterruptedException
- if interruptedpublic boolean sendOrderedBroadcast(Device device, android.content.Intent intent)
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcastpublic boolean sendOrderedBroadcast(Device device, android.content.Intent intent, android.content.BroadcastReceiver resultReceiver)
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcastresultReceiver
- the BroadcastReceiver where the ordered broadcast result should be deliveredpublic boolean sendOrderedBroadcast(Device device, android.content.Intent intent, android.content.BroadcastReceiver resultReceiver, int initialCode, java.lang.String initialData, android.os.Bundle initialExtras)
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcastresultReceiver
- the BroadcastReceiver where the ordered broadcast result should be deliveredinitialCode
- an initial value for the result code, often Activity.RESULT_OKinitialData
- an initial value for the result data, often nullinitialExtras
- an initial value for the result extras, often nullpublic Device getSendingDevice(android.content.Intent intent)
intent
- an Intentpublic static long getSendingDeviceId(android.content.Intent intent)
intent
- an Intentpublic static java.lang.String getSendingPackage(android.content.Intent intent)
intent
- an Intentpublic boolean verify(android.content.Intent intent)
intent
- an Intentpublic boolean verify(android.content.Intent intent, java.lang.String _package)
intent
- an Intent_package
- the package name to verify