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 Portal instance. Note that Liferay Screens for Xamarin is released as a NuGet package hosted in NuGet.org.
Requirements and Example Projects
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.0 (API Level 15) or above
- Liferay Portal CE or Liferay DXP
- 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.
Securing JSON Web Services
Each Screenlet in Liferay Screens calls one or more of Liferay Portal’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 Portal Configuration of JSON Web Services.
Install Liferay Screens in Xamarin Solutions
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 Portal.
Configuring Communication with Liferay Portal
Before using Liferay Screens, you must configure your project to communicate with your Liferay Portal instance. To do this, you must provide your project with the following information:
- Your portal instance’s ID.
- The ID of the portal site your app needs to communicate with.
- Your portal 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 portal 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 portal instance’s
ID. You can find this in your portal 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
portal 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 Portal CE 7.0 or Liferay DXP 7.0 instance.
Supported values are
62 for Liferay Portal 6.2, and
70 for Liferay Portal
CE 7.0 or Liferay DXP 7.0. Note that if you omit
version from these files, they default to
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 portal instance’s DDLs:
<!-- Change these values for your portal installation --> <integer name="liferay_recordset_id">20935</integer> <string name="liferay_recordset_fields">Title</string>
For additional examples of these files, see the Showcase-Android and Showcase-iOS sample projects.
Super! Your Xamarin projects are ready for Liferay Screens.
Using Screenlets in Xamarin Apps
Using Views in Xamarin.Android
Creating Xamarin Views and Themes