Get companion state in Extension Development

Hello everybody how are you all

I wanted to know that is there any way to get the companion state
I mean that the user is using companion or is using complied application

Thank you
Regards

1 Like
public boolean isCompanion(){
return activity.getPackageName().contains("edu.mit.appinventor.aicompanion");
}
5 Likes

Thank u @Know_About_IT

2 Likes

Hello,
You should also note that the companion uses a ReplForm as a screen which is subclass of the Form, which does multiple special functions intended for the companion. Unlikely the compiled apps would directly use a Form.
So you can check weather the user is using the companion or not by checking if the current form is a ReplForm or not:

public boolean isCompanion() {
  return form instanceof ReplForm;
}

Or even use the form's isRepl method to easily find out if the user is using the companion or not:

public boolean isCompanion() {
  return form.isRepl();
}

Of course, Know_About_IT's solution is valid as well.

7 Likes

Thank u @MohamedTamer for your reply
Because according to know about it I have to use if blocks for all the builder's package
But in your I have to just get the instance of repl form
Thank u @MohamedTamer again

2 Likes

This approach won't work if you expect people to use other distributions of App Inventor as their package name will be different. form.isRepl() is the ideal way to go.

7 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.