Remote broadcast service

Remote Broadcast Service is built above the DataTransactor that acrosses the machine remote service. It is used for remote broadcast sending/receiving.

Basic concept

RemoteBroadcastService

It is used for remote broadcast management. It provides the function of sending remote broadcast and registing/unregisting remote broadcast receiver.

RemoteBroadcastManager

It represents the remote broadcast manager. It is the interface provided by the remote broadcast service. The remote broadcast service operation can be performed by the user as long as the device object is acquierd.

RemoteBroadcastReceiver

It represents the remote broadcast receiver. Using the interface provided by RemoteBroadcastManager to register receiver for receiving the broadcast from remote device.

How to use

The Remote Broadcast service is a subservice of the IWDS system service, which is used in accordance with the IWDS service framework.

ServiceClient mServiceClient = new ServiceClient(mContext,
                RemoteBroadcastManager.SERVICE_REMOTE_BROADCAST, mConnectionCallbacks);
mServiceClient.connect();

//在 mConnectionCallbacks 的回调函数onConnected中获取RemoteBroadcastManager实例
public void onConnected(ServiceClient serviceClient) {
    mRemoteBroadcastManager = (RemoteBroadcastManager) serviceClient.getServiceManagerContext();

    //注册远程广播回调接口,监听远程广播的状态。
    mRemoteBroadcastManager.registerRemoteBroadcastCallback(mRemoteBroadcastCallback);
    ... ...
}

Interface

/**
 * 把意图广播到对端设备。该广播将被对端设备通过调用
 * {@link Context#registerReceiver(android.content.BroadcastReceiver, IntentFilter)}
 * 方法注册的广播接收器接收。
 * 
 * @param intent 需要广播的意图。
 * @see #sendRemoteBroadcast(Intent, String)
 */
public void sendRemoteBroadcast(Intent intent);

/**
 * 把意图广播到对端设备。该广播将被对端设备通过调用
 * {@link Context#registerReceiver(android.content.BroadcastReceiver, IntentFilter)}
 * 方法注册的广播接收器接收。
 * 
 * @param intent 需要广播的意图
 * @param perm 接收该广播需要的权限。
 * @see #sendRemoteBroadcast(Intent)
 */
public void sendRemoteBroadcast(Intent intent, String perm);

/**
 * 注册远程广播接收器。该接收器将接收对端设备通过调用{@link Context#sendBroadcast(Intent)}等方法发送的广播。
 * 
 * @param receiver 注册的远程广播接收器
 * @param filter 意图过滤器
 * @see #registerRemoteReceiver(RemoteBroadcastReceiver, IntentFilter, String)
 * @see #unregisterRemoteReceiver(RemoteBroadcastReceiver)
 */
public void registerRemoteReceiver(RemoteBroadcastReceiver receiver, IntentFilter filter);

/**
 * 注册远程广播接收器。该接收器将接收对端设备通过调用{@link Context#sendBroadcast(Intent)}等方法发送的广播。
 * 
 * @param receiver 注册的远程广播接收器
 * @param filter 意图过滤器
 * @param requestPermission 该广播接收需要的权限。
 * @see #registerRemoteReceiver(RemoteBroadcastReceiver, IntentFilter)
 * @see #unregisterRemoteReceiver(RemoteBroadcastReceiver)
 */
public void registerRemoteReceiver(RemoteBroadcastReceiver receiver, IntentFilter filter,
        String requestPermission);

/**
 * 注销远程广播接收器。注销后,应用将不再接收对端设备发送的符合接收条件的普通广播。
 * 
 * @param receiver 注销的远程广播接收器。
 * @see #registerRemoteReceiver(RemoteBroadcastReceiver, IntentFilter)
 * @see #registerRemoteReceiver(RemoteBroadcastReceiver, IntentFilter, String)
 */
public void unregisterRemoteReceiver(RemoteBroadcastReceiver receiver);

/**
 * 注册远程广播回调接口,该回调接口可以异步返回远程广播的状态。
 * <p>
 * 注意:一个实例只能注册一个回调接口,之后注册的接口会代替掉之前注册的接口,传入{@code null}可以注销回调接口。
 * 
 * @param callback 回调接口实例,为空则注销回调。
 */
public void registerRemoteBroadcastCallback(RemoteBroadcastCallback callback);

Demo

Demo:elf/samples/RemoteWakeLockTest