Using Liferay Screenlets in Android Application - ST 2024
Using Liferay Screenlets in Android Application
Liferay screenlets are visual components that a user insert into an application to use Liferay portal content and services. Liferay screenlets speeds up the development of mobile app which uses Liferay.
Liferay screenlets for android provides screenlets like Login Screenlet, Sign Up Screenlet, Forgot Password Screenlet and many more which a developer can simply integrate with an app. Developer can create his own screenlet if he wants to and can also customize the available screenlet according to the needs.
Here I am going to show how to insert a screenlet in android app which uses Liferay portal. In below example Login screenlet is used. I have used Liferay 6.2 CE GA4 Portal and Android Studio 1.3.2 for this example.
Prerequisite :
Basic knowledge of android and Liferay portal.
Android SDK with any IDE (Eclipse or Android Studio etc.) and Liferay should be properly setup.
Software Requirements:
Android Studio 1.0.2 or above.
Android SDK 4.0 (API Level 15) or above.
- Liferay Portal 6.2 CE or EE.
Step-1: Configuring android project to use Liferay screenlet.
Before using liferay screenlets, we need to configure our project with gradle. Following steps are used to configure
Liferay screens in gradle project:
Step-1(A): Add jCenter in build.gradle repositories:
repositories { } |
Step-1(B): Add liferay screens as a dependencies:
dependencies { compile 'com.liferay.mobile:liferay-screens:1.1.+' } |
Step-1(C): Add following packaging options to build.gradle file, in case if any error such as Duplicate files copied in
APK META-INF/NOTICE occurs:
android { packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } } |
Step-2: Configuring communication between liferay and screenlets.
In your project’s res/values folder, create a new file named as server_context.xml and the below code snippet
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- Change these values according to your Liferay configuration --> <string name="liferay_server">http://10.0.2.2:8080</string> <integer name="liferay_company_id">20155</integer> <integer name="liferay_group_id">20182</integer> </resources> |
Server address http://10.0.2.2:8080 is corrosponds to http://localhost:8080 through the Android studio’s emulator.
Step-3: Insert screenlet in your android app and configure them.
There are good number of Liferay Screenlets are available for variety of purposes. You just simply insert these available screenlets into your android app and configure according to your requirement. Here I will demonstrate, how to insert Login Screenlet into your android app.
Step-3(A): Open your layout XML file (eg. activity_main.xml) and insert the below Login screenlet layout code in Relative or Fragment Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:liferay="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <com.liferay.mobile.screens.auth.login.LoginScreenlet android:id="@+id/login_screenlet" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="17dp" liferay:layoutId="@layout/login_default" /> </RelativeLayout> |
Step-3(B): To listen the Liferay screenlet’s triggered event, it is needed to implement screenlet’s listener interface in
activity class. Below code snippet shows the LoginListner Implementation:
public class MainActivity implements LoginListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LoginScreenlet loginScreenlet = (LoginScreenlet) findViewById(R.id.login_screenlet); loginScreenlet.setListener(this); } @Override public void onLoginSuccess(User user) { } @Override public void onLoginFailure(Exception e) { } } |
Step-4: Once all the above steps are properly configured, then you can see your first liferay login screenlet to login into liferay server through android app.
For Your Business Requirements
2 - 4 October 2024
Hall: 10, Booth: #B8 Brussels, Belgium