PeerDeviceNet

Router API: Remote intenting

Introduction   |   Remote intenting   |   Group communication   |   Device connection   |   Java API   |   Tutorials    |   Architecture   |   Contact

Intents is Android's messaging "bus" to connect system standard components and 3rd party apps inside an android device. PeerDeviceNet extends this messaging bus to peer devices, allowing apps send remote intents. Thru PeerDeviceNet, apps can start remote activities and services, or send remote broadcasts to peer devices.

The standard android API for intent are:

PeerDeviceNet provides similar API to send remote intents. Apps should add this permission in its AndroidManifest.xml:

<uses-permission android:name="com.xconns.peerdevicenet.permission.REMOTE_INTENT" />

Please note that when sending remote intents, we can not send intents which directly access device features such as camera, GPS etc. for security reason, because they require system permissions which PeerDeviceNet may not have. For these intents, we should create customized intents and send to receiving apps at peer devices. At receiving devices, an app with right permissions will register for this customized intent and start activity using the right system intents. Please check out RemoteIntentDemo app and see how ACTION_DIAL and ACTION_CALL are handled.

Remote intenting are supported via the following three kinds of APIs.

  1. Intents api
Apps can send remote intents by calling startActivity() / startService() with a "carrier" intent defined as following:
carrierIntent.putExtra("REMOTE_INTENT", remote_intent);
carrierIntent.putExtra("PACKAGE_NAME", ...);

All the action names and data item key names are defined in Router.java.

When sending remote intents with startService(), the destination device info items must be set.

When sending remote intents with startActivity(), PeerDeviceNet will send it directly if the destination device is set inside carrier intent and already connected; otherwise it will bring up PeerDeviceNet GUI showing the list of connected devices to allow user choose which destination devices to send, or start PeerDeviceNet connection manager to search and connect to peer devices.

Please check out the source code of RemoteIntentDemo app, which shows how to use startActivity() to send remote intents. The complete source code project can be downloaded here and app can be tried out directly from Google play.

  1. IDL api
The IDL(aidl) interfaces related remote intenting are defined in two files:
Apps using IDL api will bind to the following named service:

ACTION_REMOTE_INTENT_SERVICE = "com.xconns.peerdevicenet.RemoteIntentService"

This service will expose the following asynchronous methods for sending remote intents:
IRemoteIntentService {
    oneway void startRemoteActivity(in DeviceInfo device, in Intent intent, IRemoteIntentHandler h);
    oneway void startRemoteActivityForResult(in DeviceInfo device, in Intent intent, IRemoteIntentHandler h);
    oneway void startRemoteService(in DeviceInfo device, in Intent intent, IRemoteIntentHandler h);
    oneway void sendRemoteBroadcast(in DeviceInfo device, in Intent intent, IRemoteIntentHandler h);
    oneway void cancelSession(int sessionId);
}


Apps will register the following handler to handle status of sent intents.
IRemoteIntentHandler {
    oneway void onError(in String errInfo);
    oneway void onResult(in Intent result);
    oneway void onStart(int sessionId);
    oneway void onProgress(int percent);
    oneway void onComplete();
    oneway void onRejected();
    oneway void onCanceled();
}


Please check out this RemoteIntentDemo using aidl interface.
  1. Messenger api

More details and sample code is coming.