Using Custom Portlet Services in your Android App
The Liferay Mobile SDK makes it easier to call your custom portlet services. The Liferay Mobile SDK Builder that comes with our Eclipse plugin generates libraries that enable you to access your custom portlet’s remote JSON web services.
You can also use the Liferay Mobile SDK Builder via command line. Read these instructions for more details.
You can specify a running Liferay Portal instance in Eclipse, and Eclipse queries the server for all the remote APIs that are available to generate
.jar files to access your custom portlet services. The Liferay Mobile SDK Eclipse plugin finds your custom services for you to select the ones you want to use in your app. The Mobile SDK Builder generates a
.jar file and resource files that let you access the services in from your Android app.
Now that you know the basic gist of how the Mobile SDK Eclipse plugin generates custom portlet service access libraries, let’s actually generate them for an existing Android app.
Right-click your Android app project in the Package Explorer and select Configure → Generate services for Liferay custom portlets. This opens a wizard where you’ll specify your running portal server.
Figure 9.7: The Mobile SDK wizard lets you specify your Liferay portal server connection and conveniently provides the means to test that connection.
Specify your server’s URL, Username, and Password. Notice the Status and Summary fields; these fields indicate your running portal instance’s status after clicking the Check Status button.
The plugin saves previously configured server instance connection information in a listing at the bottom so that you can configure your Android app to use any previously configured portal server. Each server’s URL and Last Available Summary is displayed.
Once you’ve checked the status of your server, click Next. The plugin queries the server you specified for all the remote APIs that are available, and generates for your custom portlet services.
In the next menu, specify the Java package for the SDK source code that the builder generates. Then select the custom portlet APIs that you want to access.
Figure 9.8: Liferay’s Mobile SDK Builder queries all remote APIs that are available for generating SDK libraries to provide access to custom portlet services.
For demonstration purposes, we’ll specify the Java package as
com.liferay.custom and select an arbitrary custom API (such as the opensocial-portlet → gadget custom API shown in the figure below).
Figure 9.9: The Mobile SDK Eclipse plugin injects the Android app with the appropriate
.properties files to use in accessing the custom portlet APIs.
Notice that you have the standard and custom
.properties files. When generating custom services, Eclipse adds both the standard JAR file used for accessing Liferay core services and utilities and a custom JAR file for accessing your custom portlet services.
You’ve generated custom services for your Liferay portlets! Now your app can access Liferay core services, Liferay utilities, and your custom portlet services.
Now that your Android app has the access it needs to use Liferay and your custom portlets, let’s take an in-depth look at using the Android SDK to invoke their services.