Skill manager
The skill manager service provides APIs to handle operations related to skills , including controlling skill status, monitoring skill status and changes, and distributing skill instructions. As the skill management service access agent, SkillManager provides the main API of the skill management service, which can be obtained through RobotContext .
SkillManager skillManager = robotContext.getSystemService(SkillManager.SERVICE);
Control skill status
In the Cruzr system, in most cases, the status of skills is managed through system decision-making. For developers who need to actively control the status of skills, skill management also provides interfaces for processing.
Pause the skill
promise /* [1] */ = skillManager.pauseSkill("com.xxx.pkg", "music" /* [2] */) .done(new DoneCallback<Void>() { @Override public void onDone(Void aVoid) { // if the callback is successful, it will be executed here } }) .fail(new FailCallback<SkillOperationException>() { @Override public void onFail(SkillOperationException e) { // if the callback has failed, it will be executed here } });
[1] The asynchronous object that returns the results of the pause skill. For specific usage, refer to Promise
[2]To pause the skill, the packagename and `skill name need to be provided.skill
Stop the skill
promise = skillManager.stopSkill("com.xxx.pkg", "music");
The operation of stopping skills is similar to that of pausing skills, which will not be described in detail here.
Listen the changes of skill status
When the skill status changes, the Cruzr system will send event notifications, and skill management provides an interface to monitor the status changes of skills in the system.
skillManager.registerSkillLifecycleCallbacks(new SkillLifecycleCallbacks() { @Override public void onSkillStarted(SkillInfo skillInfo /* [1] */ ) { // If the skill is started, it will be noticed here } @Override public void onSkillPaused(SkillInfo skillInfo, SkillPauseCause skillPauseCause /* [2] */) { // If the skill is paused, it will be noticed here } @Override public void onSkillStopped(SkillInfo skillInfo, SkillStopCause skillStopCause /* [3] */) { // If the skill is stopped, it will be noticed here } });
[1] SkillInfo contains the detailed information of skills, the parameters are as follows:
| Attribute getter | Descriptions |
|---|---|
| SkillInfo.name | Skill name, refer to Configure Skills |
| SkillInfo.className | Skill name, Java class name |
| SkillInfo.packageName | The package name of the process where the skill is located |
| SkillInfo.isSystemPackage | Whether the process where the skill is located is a system process |
| SkillInfo.directiveList | A list of skill instructions. For details, refer to Configuration Instructions. |
[2] SkillPauseCause The cause for pausing the skill. For details, refer to Skill Status.
[3] SkillStopCause The cause for stopping the skill. For details, refer to Skill Status.
Inter-process instruction distribution
Cruzr developers often send instructions to other process skills. Skill management provides interfaces to distribute inter-process instructions. For in-process instruction distribution, see Context
JSONObject jsonObject = new JSONObject(); jsonObject.put("test", "test"); Music music = new Music("xxx/xxx.pm3", "singer"); Directive directive /* [1] */ = Directive.Builder .fromAction(Directive.SOURCE_INTER_PROCESS, "music/play") /* [2] */ .setSourceExtra(JsonObjectString.from(jsonObject)) /* [3] */ .setParam(music, ContentTypes.PARCELABLE) /* [4] */ .build(); skillManager.dispatchDirective(directive) .done(new DoneCallback<Void>() { @Override public void onDone(Void aVoid) { // if the distribution is successful, it will be executed here } }) .fail(new FailCallback<DispatchException>() { @Override public void onFail(DispatchException e) { // if the distribution has failed, it will be executed here } });
[1] Directive uses an instruction object that sends instructions. For details, refer to the instruction object.
[2] Specifying the instruction source is an inter-process, the instruction action is "music / play"
[3]Customized information carried by the instruction source
[4] The instruction contains parameters, and the specified type is ContentTypes.PARCELABLE, where music must be a parcelable type. For other types, refer to serialization type.
[5]To pause the skill, the packagename and `skill name need to be provided.skill