Package com.vuzix.connectivity.sdk
Class Connectivity
java.lang.Object
com.vuzix.connectivity.sdk.Connectivity
The Connectivity class is the main entry point into the Connectivity SDK.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
DeviceListeners are interested in all events that could happen with Connectivity.static class
Convenience class for implementing a DeviceListener without having to implement all methods.static class
A simple data-struct to pass the results of a synchronous ordered broadcast around -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.Convenience method for obtaining a remote device.getDevice
(long id) Returns a device with the specified id.Returns a list of all available remote devices that are linked to this 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 String
getSendingPackage
(android.content.Intent intent) Determines the remote package (app) that sent the intent.boolean
Determines if Connectivity is available on this device.boolean
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
Removes a DeviceListener.boolean
sendBroadcast
(android.content.Intent intent) Sends a broadcast to all connected remote devices.boolean
sendBroadcast
(Device device, android.content.Intent intent) Sends a broadcast to the specified remote device.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, BroadcastResultReceiver resultReceiver) Sends an ordered broadcast to the specified remote device.boolean
sendOrderedBroadcast
(Device device, android.content.Intent intent, BroadcastResultReceiver resultReceiver, int initialCode, String initialData, android.os.Bundle initialExtras) Sends an ordered broadcast to the specified remote device.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
Determines if the given intent is a valid intent that came from the Connectivity framework and that it originated from the specified package.
-
Field Details
-
ACTION_DEVICE_ADDED
- See Also:
-
ACTION_DEVICE_CHANGED
- See Also:
-
ACTION_DEVICE_REMOVED
- See Also:
-
ACTION_DEVICE_CONNECTED
- See Also:
-
ACTION_DEVICE_DISCONNECTED
- See Also:
-
ACTION_ORDERED_BROADCAST_RESULT
- See Also:
-
EXTRA_DEVICE_ID
- See Also:
-
EXTRA_SENDING_PACKAGE
- See Also:
-
EXTRA_VERIFY_DATA
- See Also:
-
EXTRA_VERIFY_SIGNATURE
- See Also:
-
EXTRA_BROADCAST_ID
- See Also:
-
EXTRA_BROADCAST_RESULT_CODE
- See Also:
-
EXTRA_BROADCAST_RESULT_DATA
- See Also:
-
EXTRA_BROADCAST_RESULT_EXTRAS
- See Also:
-
-
Method Details
-
get
Returns the global Connectivity object associated with your application.- Parameters:
context
- a Context- Returns:
- a Connectivity object
-
addDeviceListener
Adds a DeviceListener which will be notified when Connectivity events happen. Be sure to call removeDeviceListener(DeviceListener) when your listener is no longer needed.- Parameters:
listener
- the DeviceListener to add
-
removeDeviceListener
Removes a DeviceListener.- Parameters:
listener
- the DeviceListener to remove
-
isAvailable
public boolean isAvailable()Determines if Connectivity is available on this device. If Connectivity is not available, no further calls should be made on this class.- Returns:
- true if Connectivity is available, false otherwise
-
getDevices
Returns a list of all available remote devices that are linked to this device.- Returns:
- a List of Device objects
-
getDevice
Returns a device with the specified id.- Parameters:
id
- the id of a Device- Returns:
- a Device object or null if the device id was not found
-
getDevice
Convenience method for obtaining a remote device. This method should only be used if it is expected that only one remote device could be linked.- Returns:
- a Device object or null if there are no remote devices
-
isLinked
public boolean isLinked()Determines if any remote devices are linked.- Returns:
- true if this device has any linked remote devices, false otherwise
-
isConnected
public boolean isConnected()Determines if any remote devices are currently connected.- Returns:
- true if any remote devices are currently connected, false otherwise
-
isConnected
Determines if the specified device is currently connected.- Parameters:
device
- a Device- Returns:
- true if the device is connected, false otherwise
-
sendBroadcast
public boolean sendBroadcast(android.content.Intent intent) Sends a broadcast to all connected remote devices.- Parameters:
intent
- the Intent to send as a broadcast- Returns:
- true if the broadcast was successfully sent, false otherwise
-
sendBroadcast
Sends a broadcast to the specified remote device.- Parameters:
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcast- Returns:
- true if the broadcast was successfully sent, false otherwise
-
sendSynchronousOrderedBroadcast
public Connectivity.SynchronousOrderedBroadcastResult sendSynchronousOrderedBroadcast(Device device, android.content.Intent intent) throws InterruptedException Synchronously send an ordered broadcast message to a remote device. NOTE: DO NOT CALL FROM MAIN THREAD!- Parameters:
device
- the Device to send request tointent
- the Intent to send as a broadcast- Returns:
- a SynchronousOrderedBroadcastResult or null if the underlying sendOrderedBroadcast fails
- Throws:
InterruptedException
- if interrupted
-
sendOrderedBroadcast
Sends an ordered broadcast to the specified remote device.- Parameters:
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcast- Returns:
- true if the broadcast was successfully sent, false otherwise
-
sendOrderedBroadcast
public boolean sendOrderedBroadcast(Device device, android.content.Intent intent, BroadcastResultReceiver resultReceiver) Sends an ordered broadcast to the specified remote device.- Parameters:
device
- the Device to send the broadcast tointent
- the Intent to send as a broadcastresultReceiver
- the BroadcastReceiver where the ordered broadcast result should be delivered- Returns:
- true if the broadcast was successfully sent, false otherwise
-
sendOrderedBroadcast
public boolean sendOrderedBroadcast(Device device, android.content.Intent intent, BroadcastResultReceiver resultReceiver, int initialCode, String initialData, android.os.Bundle initialExtras) Sends an ordered broadcast to the specified remote device.- Parameters:
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 null- Returns:
- true if the broadcast was successfully sent, false otherwise
-
getSendingDevice
Determines the remote device that sent the given intent.- Parameters:
intent
- an Intent- Returns:
- the Device that send the intent or null if the sender could not be determined
-
getSendingDeviceId
public static long getSendingDeviceId(android.content.Intent intent) Extracts the device id from an intent.- Parameters:
intent
- an Intent- Returns:
- the device id that send the intent or null if the device id could not be determined
-
getSendingPackage
Determines the remote package (app) that sent the intent.- Parameters:
intent
- an Intent- Returns:
- the remote package name or null if the remote package could not be determined
-
verify
public boolean verify(android.content.Intent intent) Determines if the given intent is a valid intent that came from the Connectivity framework. Use this method to verify an intent was not spoofed locally by another app.- Parameters:
intent
- an Intent- Returns:
- true if the intent came through Connectivity, false otherwise
-
verify
Determines if the given intent is a valid intent that came from the Connectivity framework and that it originated from the specified package. Use this method to verify an intent was not spoofed locally by another app.- Parameters:
intent
- an Intent_package
- the package name to verify- Returns:
- true if the intent came through Connectivity from the specified package, false otherwise
-