To use Liferay Screens with Xamarin, you must install Screens in your Xamarin project. You must then configure your project to communicate with your Liferay DXP instance. Note that Liferay Screens for Xamarin is released as a NuGet package hosted in NuGet.org.
Liferay Screens for Xamarin includes the bindings necessary to use all Screenlets included with Screens. The following software is required:
- Visual Studio
- Android SDK 4.1 (API Level 16) or above
- Liferay CE Portal 7.0/7.1, or Liferay DXP 7.0
- Liferay Screens NuGet package
Also note that if you get confused or stuck while using Screens for Xamarin, the official Liferay Screens repository contains two sample Xamarin projects that you can reference:
Showcase-Android: An example app for Xamarin.Android containing all the currently available Screenlets.
Showcase-iOS: An example app for Xamarin.iOS containing all the currently available Screenlets.
Each Screenlet in Liferay Screens calls one or more of Liferay DXP’s JSON web services, which are enabled by default. The Screenlet reference documentation for Android and iOS lists the web services that each Screenlet calls. To use a Screenlet, its web services must be enabled in the portal. It’s possible, however, to disable the web services needed by Screenlets you’re not using. For instructions on this, see the tutorial Configuring JSON Web Services. You can also use Service Access Policies for more fine-grained control over accessible services.
Follow these steps to install Liferay Screens in your Xamarin project:
Open your project in Visual Studio.
Right click your project’s Packages folder and then select Add packages….
Look for LiferayScreens and install the latest version.
Accept the license agreements for any dependencies. These are necessary to use Liferay Screens in Xamarin.
Check your configuration one of these ways:
- Rebuild and execute your project, and import a Liferay Screens path
- In your project, select References → From Packages and look for
LiferayScreens*file. Open that file in the Assembly Browser. You should then see all the available Liferay Screens files.
- Rebuild and execute your project, and import a Liferay Screens path (e.g.,
Next, you’ll set up communication with Liferay DXP.
Before using Liferay Screens, you must configure your project to communicate with your Liferay DXP instance. To do this, you must provide your project with the following information:
- Your Liferay DXP instance’s ID.
- The ID of the Liferay DXP site your app needs to communicate with.
- Your Liferay DXP instance’s version.
- Any other information required by specific Screenlets.
Fortunately, this is straightforward. Do the following in your Xamarin projects:
For Xamarin.Android, create a new file called
Resources/valuesfolder. Add the following code to this file:
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- Change these values for your portal installation --> <string name="liferay_server">http://10.0.2.2:8080</string> <integer name="liferay_company_id">20116</integer> <integer name="liferay_group_id">20143</integer> <integer name="liferay_portal_version">70</integer> </resources>
For Xamarin.iOS, create a new file called
Resourcesfolder. Add the following code to this file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>server</key> <string>http://localhost:8080</string> <key>version</key> <integer>70</integer> <key>companyId</key> <real>20116</real> <key>groupId</key> <real>20143</real> </dict> </plist>
Make sure to change these values to match those of your Liferay DXP instance. The
http://10.0.2.2:8080 is suitable for testing with Android
Studio’s emulator, because it corresponds to
localhost:8080 through the
emulator. If you’re using the Genymotion emulator, you should, however, use
192.168.56.1 instead of
companyId values are your Liferay DXP instance’s
ID. You can find this in your Liferay DXP instance at Control Panel →
Configuration → Virtual Instances. The instance’s ID is in the
Instance ID column.
groupId values are the ID of the site your app
needs to communicate with. To find this value, first go to the site in your
Liferay DXP instance that you want your app to communicate with. In the Site
Administration menu, select Configuration → Site Settings. The site
ID is listed at the top of the General tab.
70 tells Screens that it’s
communicating with a Liferay CE Portal 7.0 or Liferay DXP 7.0 instance. Here are
the supported values and the portal versions they correspond to:
71: Liferay CE Portal 7.1 or Liferay DXP 7.1
70: Liferay CE Portal 7.0 or Liferay DXP 7.0
62: Liferay Portal 6.2 CE/EE
You can also configure Screenlet properties in
liferay-server-context.plist. The example
liferay_recordset_fields, enable DDL
Form Screenlet and DDL List Screenlet to interact with a Liferay DXP instance’s
<!-- Change these values for your portal installation --> <integer name="liferay_recordset_id">20935</integer> <string name="liferay_recordset_fields">Title</string>
Super! Your Xamarin projects are ready for Liferay Screens.