Sending commands
All commands will use the JSON-RPC 2.0 protocol: www.jsonrpc.org/specification
There are two ways to send RNC commands:
The command JSON always travels in the string extra BND_MESSAGE, on both transports. It is not method and not rnc_command. A broadcast without that extra is discarded silently - no response is sent.
Send command to activity: This is the appropriate method if the receiving application must be put in the foreground when command is received.
Pros:
- The receiving application will be brought to the foreground automatically
Cons:
- The sending application must be in the foreground when sending the command.
Example of usage:
Java
java
String SEND_ACTION = "ACTION_RNC_BROADCAST";
String SEND_PACKAGE = "com.benomad.benav";
String SEND_CLASS = "com.benomad.benav.MainActivity";
String EXTRA_NAME = "BND_MESSAGE";
Intent i = new Intent(SEND_ACTION);
i.setPackage(SEND_PACKAGE);
i.setComponent(new ComponentName(SEND_PACKAGE, SEND_CLASS));
i.putExtra(EXTRA_NAME, "{\"jsonrpc\":\"2.0\",\"method\":\"getAppInfo\",\"id\":\"1\"}");
startActivity(i);Kotlin
kotlin
val SEND_ACTION = "ACTION_RNC_BROADCAST"
val SEND_PACKAGE = "com.benomad.benav"
val SEND_CLASS = "com.benomad.benav.MainActivity"
val EXTRA_NAME = "BND_MESSAGE"
val i = Intent(SEND_ACTION)
i.setPackage(SEND_PACKAGE)
i.component = ComponentName(SEND_PACKAGE, SEND_CLASS)
i.putExtra(
EXTRA_NAME,
"{\"jsonrpc\":\"2.0\",\"method\":\"getAppInfo\",\"id\":\"1\"}"
)
startActivity(i)Send command to service: Use this method when the application must stay in the background while processing commands.
Pros:
- The sending application can be in the foreground or background while sending the command
Cons:
- The receiving application can't be put in the foreground.
This limitation can be bypassed by enabling "Allow display over other apps" in the receiving application's settings. On Android 10+, the receiving application must grant the SYSTEM_ALERT_WINDOW permission.
Example of usage
Example of usage:
Java
java
String SEND_ACTION = "ACTION_RNC_BROADCAST";
String SEND_PACKAGE = "com.benomad.benav";
String SEND_CLASS = "com.benomad.move.rnc_domain.RNCBroadcastReceiver";
String EXTRA_NAME = "BND_MESSAGE";
Intent i = new Intent(SEND_ACTION);
i.setPackage(SEND_PACKAGE);
i.setComponent(new ComponentName(SEND_PACKAGE, SEND_CLASS));
i.putExtra(EXTRA_NAME, "{\"jsonrpc\":\"2.0\",\"method\":\"getAppInfo\",\"id\":\"1\"}");
sendBroadcast(i);Kotlin
kotlin
val SEND_ACTION = "ACTION_RNC_BROADCAST"
val SEND_PACKAGE = "com.benomad.benav"
val SEND_CLASS = "com.benomad.move.rnc_domain.RNCBroadcastReceiver"
val EXTRA_NAME = "BND_MESSAGE"
val i = Intent(SEND_ACTION)
i.setPackage(SEND_PACKAGE)
i.component = ComponentName(SEND_PACKAGE, SEND_CLASS)
i.putExtra(
EXTRA_NAME,
"{\"jsonrpc\":\"2.0\",\"method\":\"getAppInfo\",\"id\":\"1\"}"
)
sendBroadcast(i)Commands responses