<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>WebScreenlet Session for Device registration for Android Push notification</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110809321" />
  <subtitle>WebScreenlet Session for Device registration for Android Push notification</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110809321</id>
  <updated>2026-04-04T07:56:07Z</updated>
  <dc:date>2026-04-04T07:56:07Z</dc:date>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110942349" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110942349</id>
    <updated>2018-09-13T08:52:09Z</updated>
    <published>2018-09-13T08:52:09Z</published>
    <summary type="html">&lt;p&gt;Thanks for your help Victor. I am able to register the device with
  above approach and also push notifications are working fine.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-09-13T08:52:09Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110902113" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110902113</id>
    <updated>2018-09-07T09:05:25Z</updated>
    <published>2018-09-07T09:05:25Z</published>
    <summary type="html">&lt;p&gt;Thanks Victor for detailed explanation with example.  I will try it
  and update you.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-09-07T09:05:25Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110895295" />
    <author>
      <name>Victor Galan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110895295</id>
    <updated>2018-09-06T10:50:52Z</updated>
    <published>2018-09-06T10:50:52Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hey!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You need to get the cookies from the Webview itself, using android
  classes. Let me try to explain the whole process:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- First, you load the webscreenlet with your page as you are doing&lt;/p&gt;
&lt;p&gt;- You have to detect when you have logged in the webview. Implement
  weblistener a check it in the OnPageLoaded method.&lt;/p&gt;
&lt;p&gt;- Once you are logged, you have to execute a script in the webView to
  grab the authToken. For doing this you have to create a Script a
  inject it:&lt;/p&gt;
&lt;pre&gt;
JsScript script = &lt;span&gt;new &lt;/span&gt;JsScript(&lt;span&gt;"session"&lt;/span&gt;, &lt;span&gt;"window.Screens.postMessage('token', Liferay.authToken);"&lt;/span&gt;);

&lt;span&gt;webScreenlet&lt;/span&gt;.injectScript(script);&lt;/pre&gt;
&lt;p&gt;This script will take the authToken and send it to the native part.
  You will receive it in the OnScriptMessageHandler listener method.&lt;/p&gt;
&lt;p&gt;- Now, after receiving the authToken, you will have to get the cookies:&lt;/p&gt;
&lt;pre&gt;
String cookieHeader = CookieManager.&lt;span&gt;getInstance&lt;/span&gt;().getCookie(&lt;span&gt;&amp;lt;url-of-your-server&amp;gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;With this two things you can create an ephemeral authentication:&lt;/p&gt;
&lt;pre&gt;
CookieAuthentication cookieAuthentication = &lt;span&gt;new &lt;/span&gt;CookieAuthentication(authToken, cookieHeader, &lt;span&gt;""&lt;/span&gt;, &lt;span&gt;""&lt;/span&gt;, &lt;span&gt;false&lt;/span&gt;, &lt;span&gt;0&lt;/span&gt;, &lt;span&gt;0&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;- With this authentication you can create a session&lt;/p&gt;
&lt;pre&gt;
Session session = &lt;span&gt;new &lt;/span&gt;SessionImpl(&lt;span&gt;"http://screens.liferay.org.es"&lt;/span&gt;, cookieAuthentication);&lt;/pre&gt;
&lt;p&gt;- Lastly, you can use this session to register the device:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Push.with(session).register(this, YOUR_SENDER_ID);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You have a project with a working example&amp;nbsp; &lt;a href="https://github.com/victorg1991/CookieAuthFromWebScreenlet"&gt;here&lt;/a&gt;
  it is calling an arbitrary jsonws service, but it will work with all
  of them.&lt;/p&gt;
&lt;p&gt;I hope it helps&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Victor Galan</dc:creator>
    <dc:date>2018-09-06T10:50:52Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110892999" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110892999</id>
    <updated>2018-09-06T06:41:02Z</updated>
    <published>2018-09-06T06:41:02Z</published>
    <summary type="html">&lt;p&gt;Thanks Javier,&lt;/p&gt;
&lt;p&gt;I was following approach suggested by you and wanted to get cookies
  from portal and then post it to webscreenlet using &lt;strong&gt;onScriptMessageHandler&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But when I tried getting cookies at portal side using
  document.cookie, It does not provide &lt;strong&gt;httpcookie&lt;/strong&gt;. For
  example, JSESSIONID, SAML_SP_SESSION_KEY etc are not availble in list
  fetched. How can I retrieve all cookies and create Session (using
  CookieAuthentication) with those cookies without username and password?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-09-06T06:41:02Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110879945" />
    <author>
      <name>Javier Gamarra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110879945</id>
    <updated>2018-09-04T21:06:09Z</updated>
    <published>2018-09-04T21:06:09Z</published>
    <summary type="html">&lt;p&gt;As per my understanding, device registration is speific to user not
  with role. So initially every user of my portal, who has installed app
  and logged in, will get his device registered for Push Notifications
  and then while sending notification, we will be having role based
  notifications, so will be sending notification to al users under that
  role. My Challenge is to register device with user.&lt;/p&gt;
&lt;p&gt; -&amp;gt; Yes, everything is correct.&lt;/p&gt;
&lt;p&gt;Yes, this is what I shared in my last post. I got the loggedin userId
  from WebScreenLet javascript (OnScriptMessageHandler) but cannot do
  much with this userId.&lt;/p&gt;
&lt;p&gt;My Challenge is to create Session for device registration. I called
  UserConnector as per your suggestion by using admin/default user
  session but then stuck as it will not help me to create session for
  logged in user. &lt;/p&gt;
&lt;p&gt;I also called RoleService using default/admin user to get role of
  logged in user but then also cannot get Session to register device. As
  per last suggestion if I create default user for each role and pass it
  to make session, I will be exposing lot of users credentials. My
  question was, if it ok to do that?&lt;/p&gt;
&lt;p&gt;-&amp;gt; It would be Ok. But you would have to modify several things.
  Cookie Auth, explained below is better :)&lt;/p&gt;
&lt;p&gt;Even in above approach, I will be requiring user's password to create
  session. Do you have working example for this? &lt;/p&gt;
&lt;p&gt;-&amp;gt; That's what I didn't explain correctly. There is a method to
  create the session with the Cookie (and another for OAuth or token
  auth). You can create a Session with new SessionImpl(IP, new
  BasicAuthentication()) but also with new CookieAuthentication and that
  class it &lt;strong&gt;doesn't need the user and password&lt;/strong&gt;, just
  things that you can capture in the WebView.&lt;/p&gt;</summary>
    <dc:creator>Javier Gamarra</dc:creator>
    <dc:date>2018-09-04T21:06:09Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110874670" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110874670</id>
    <updated>2018-09-04T09:25:32Z</updated>
    <published>2018-09-04T09:25:32Z</published>
    <summary type="html">&lt;p&gt;HI Javier,&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;If you just want to register a role, instead of a user, yes.
    But, if I understand correctly, that's not what you want, you need
    to send notifications to a specific users (but with a logic based on
    the role).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As per my understanding, device registration is speific to user not
  with role. So initially every user of my portal, who has installed app
  and logged in, will get his device registered for Push Notifications
  and then while sending notification, we will be having role based
  notifications, so will be sending notification to al users under that
  role. My Challenge is to register device with user.&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;The idea would be doing the same request but also sending the
    userId (and do the role logic on the server). We would have to
    modify the push library.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Yes, this is what I shared in my last post. I got the loggedin userId
  from WebScreenLet javascript (OnScriptMessageHandler) but cannot do
  much with this userId.&lt;/p&gt;
&lt;p&gt;My Challenge is to create Session for device registration. I called
  UserConnector as per your suggestion by using admin/default user
  session but then stuck as it will not help me to create session for
  logged in user. &lt;/p&gt;
&lt;p&gt;I also called RoleService using default/admin user to get role of
  logged in user but then also cannot get Session to register device. As
  per last suggestion if I create default user for each role and pass it
  to make session, I will be exposing lot of users credentials. My
  question was, if it ok to do that?&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;But talking with Víctor... he has recommended the cookie
    approach... does it work for you?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;You can capture a valid cookie to do a login/push request
    with CookieManager.sync().getCookie(url) and capture the authToken
    through javascript in the webview. With that you can create a valid
    CookieAuthentication and pass that do the push service and will be a
    valid authentication to that user.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Even in above approach, I will be requiring user's password to create
  session. Do you have working example for this? &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-09-04T09:25:32Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110841611" />
    <author>
      <name>Javier Gamarra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110841611</id>
    <updated>2018-08-30T08:32:26Z</updated>
    <published>2018-08-30T08:32:26Z</published>
    <summary type="html">&lt;p&gt;If you just want to register a role, instead of a user, yes. But, if
  I understand correctly, that's not what you want, you need to send
  notifications to a specific users (but with a logic based on the role).&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The idea would be doing the same request but also sending the userId
  (and do the role logic on the server). We would have to modify the
  push library.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;But talking with Víctor... he has recommended the cookie
    approach... does it work for you?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You can capture a valid cookie to do a login/push request
  with CookieManager.sync().getCookie(url) and capture the authToken
  through javascript in the webview. With that you can create a valid
  CookieAuthentication and pass that do the push service and will be a
  valid authentication to that user.&lt;/p&gt;</summary>
    <dc:creator>Javier Gamarra</dc:creator>
    <dc:date>2018-08-30T08:32:26Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110829718" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110829718</id>
    <updated>2018-08-29T09:03:55Z</updated>
    <published>2018-08-29T09:03:55Z</published>
    <summary type="html">&lt;p&gt;So If I am understanding it correctly, first I have to call
  RoleService by passing default user authentication and then by passing
  actual userId, need to identify its role. &lt;/p&gt;
&lt;pre&gt;
       Session session = new SessionImpl(&amp;quot;http://xyz.com&amp;quot;, new BasicAuthentication(&amp;quot;test&amp;quot;,&amp;quot;test&amp;quot;));
       RoleService roleService = new RoleService(session);
       JSONArray roleList = new JSONArray();
       try {
           roleList = roleService.getUserRoles(Long.parseLong(actualUser));
           Log.i(TAG, &amp;quot;Role List&amp;quot;+roleList);
        } catch (Exception e) {
            e.printStackTrace();
         }&lt;/pre&gt;
&lt;p&gt;Once we get role of actual user (SAML user), We need to create
  session using default user with same role as actual user. There will
  be lot of if/else conditions to achieve that and also not sure, if
  exposing these many credentials in code is correct or not (We have 10 roles). &lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;&amp;quot;You would have to modify a small part of the mobile
    client (we can help with that) and add a hook/code in the portal. &amp;quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thanks, please suggest.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-08-29T09:03:55Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110829034" />
    <author>
      <name>Javier Gamarra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110829034</id>
    <updated>2018-08-29T06:43:11Z</updated>
    <published>2018-08-29T06:43:11Z</published>
    <summary type="html">&lt;p&gt;Yes, I mean using a default user just for calling the json ws
  services and passing the userId as one of the arguments. You could
  check the role of the userId or the permissions inside the service.
  You would have to modify a small part of the mobile client (we can
  help with that) and add a hook/code in the portal. &lt;/p&gt;</summary>
    <dc:creator>Javier Gamarra</dc:creator>
    <dc:date>2018-08-29T06:43:11Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110828316" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110828316</id>
    <updated>2018-08-29T04:25:54Z</updated>
    <published>2018-08-29T04:25:54Z</published>
    <summary type="html">&lt;p&gt;Thanks for your response Javier.&lt;/p&gt;
&lt;p&gt;&amp;quot;The best way would be decoupling the userId needed for push
  with the authentication needed for the request, that way you could use
  a default user created just for registering users in the portal (with
  just those permissions). It would have several inconveniences (it can
  be leaked, but at least you can invalid it, you have to hardcode
  something...). If you want to follow this approach we can help you
  modifying the code.&amp;quot;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Do you mean to say for registering device, I should use a default
  user rather than using actual user who owns the device? How will we
  implement Role based notification then? or you mean to say create one
  default user for each role and then while registering device, check
  role of actual user and register device with default user of same role?&lt;/p&gt;
&lt;p&gt;We are having users with different roles and notification will be
  send to set of users having specific role  for specific case.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-08-29T04:25:54Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110825509" />
    <author>
      <name>Javier Gamarra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110825509</id>
    <updated>2018-08-28T18:12:23Z</updated>
    <published>2018-08-28T18:12:23Z</published>
    <summary type="html">&lt;p&gt;Yep, I see... you don't have a lot of options.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You can either capture the user/password with a WebView when they
  login against ADFS (fragile and insecure), use CookieAuthentication in
  the session and hope that the cookie is valid for the portal or
  configure another, preferably token-based authentication
  method (complementary with SAML) or disable authentication for that
  endpoint (or adding a filter to authenticate based on other
  information)... I think that is all :(&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The best way would be decoupling the userId needed for push with the
  authentication needed for the request, that way you could use a
  default user created just for registering users in the portal (with
  just those permissions). It would have several inconveniences (it can
  be leaked, but at least you can invalid it, you have to hardcode
  something...). If you want to follow this approach we can help you
  modifying the code.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Maybe @VictorGalan can shed more light about disabling/changing
  security in that endpoint. Pinging him internally.&lt;/p&gt;</summary>
    <dc:creator>Javier Gamarra</dc:creator>
    <dc:date>2018-08-28T18:12:23Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110824812" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110824812</id>
    <updated>2018-08-28T15:15:45Z</updated>
    <published>2018-08-28T15:15:45Z</published>
    <summary type="html">&lt;p&gt;I can get user and create session in case of basic authentication for
  portal users  but in our case we are using SAML authentication and
  Identity provider is ADFS.&lt;/p&gt;
&lt;p&gt;In our case, password is being managed at ADFS side. So how will we
  able to create session by passing username and password?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;And also to access &lt;strong&gt;UserConnector &lt;/strong&gt;object, we will
  require session object :&lt;/p&gt;
&lt;p&gt;https://github.com/liferay/liferay-screens/blob/develop/android/library/src/main/java/com/liferay/mobile/screens/auth/login/connector/UserConnector62.java&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-08-28T15:15:45Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110822483" />
    <author>
      <name>Sarai Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110822483</id>
    <updated>2018-08-28T12:24:05Z</updated>
    <published>2018-08-28T12:24:05Z</published>
    <summary type="html">&lt;p&gt;You can use UserConnector to get the user from its userId: &lt;a href="https://github.com/liferay/liferay-screens/blob/develop/android/library/src/main/java/com/liferay/mobile/screens/auth/login/connector/UserConnector.java"&gt;https://github.com/liferay/liferay-screens/blob/develop/android/library/src/main/java/com/liferay/mobile/screens/auth/login/connector/UserConnector.java&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And then, create the session with the username and password.&lt;/p&gt;
&lt;p&gt;Hope it helps.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Sarai&lt;/p&gt;</summary>
    <dc:creator>Sarai Diaz</dc:creator>
    <dc:date>2018-08-28T12:24:05Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110822459" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110822459</id>
    <updated>2018-08-28T11:58:33Z</updated>
    <published>2018-08-28T11:58:33Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Thanks Sarai.&lt;/p&gt;
&lt;p&gt;I was able to get userId from themeDisplay in my javascript and then
  I was able to post it app:&lt;/p&gt;
&lt;pre&gt;
window.Screens.postMessage('userId', userId);&lt;/pre&gt;
&lt;p&gt;But now for registering device, we need to have Session object as per
  below API:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Push.with(session).register(this, YOUR_SENDER_ID);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do we have any API to get session in WebScreenLet or session from
  userId? as below API will not work in my case:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Session session = new SessionImpl(YOUR_SERVER, new BasicAuthentication(YOUR_USER, YOUR_PASSWORD));&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Push.with(SessionContext.createSessionFromCurrentSession()).register(this, YOUR_SENDER_ID);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-08-28T11:58:33Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110820315" />
    <author>
      <name>Sarai Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110820315</id>
    <updated>2018-08-28T08:20:33Z</updated>
    <published>2018-08-28T08:20:33Z</published>
    <summary type="html">&lt;p&gt;You can add a JavaScript file from three different sources: locally, 
  remotely or from Android Studio raw folder.&lt;/p&gt;
&lt;p&gt;Please see the documentation: &lt;a href="https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/web-screenlet-for-android#configuration"&gt;https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/web-screenlet-for-android#configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Inside your JavaScript file you can access Screens object, to post a
  message from JavaScript to native and do whatever you want inside the
  method I mentioned in the previous reply. Also, in the JavaScript file
  you can access themeDisplay to check userId or other properties.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Sarai&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Sarai Diaz</dc:creator>
    <dc:date>2018-08-28T08:20:33Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110819307" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110819307</id>
    <updated>2018-08-28T06:25:08Z</updated>
    <published>2018-08-28T06:25:08Z</published>
    <summary type="html">&lt;p&gt;Thanks Sarai for your reply.&lt;/p&gt;
&lt;p&gt;Where can I write this javascript and will I able to get Liferay
  objects like themeDisplay inside? Do you have any example code?&lt;/p&gt;
&lt;p&gt;It seems SessionContext also will not work in case of WebScreenlets.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-08-28T06:25:08Z</dc:date>
  </entry>
  <entry>
    <title>RE: WebScreenlet Session for Device registration for Android Push notificat</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110815086" />
    <author>
      <name>Sarai Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110815086</id>
    <updated>2018-08-27T12:01:38Z</updated>
    <published>2018-08-27T12:01:38Z</published>
    <summary type="html">&lt;p&gt;Hello Ankit,&lt;/p&gt;
&lt;p&gt;You can create a JavaScript file with the logic (when the user is
  logged in the application) and inject it in the WebScreenlet. Then,
  you can control whatever you want in this method:&lt;/p&gt;
&lt;pre&gt;
public void onScriptMessageHandler(String namespace, String body)&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Sarai&lt;/p&gt;</summary>
    <dc:creator>Sarai Diaz</dc:creator>
    <dc:date>2018-08-27T12:01:38Z</dc:date>
  </entry>
  <entry>
    <title>WebScreenlet Session for Device registration for Android Push notification</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110809320" />
    <author>
      <name>Ankit Srivastava</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110809320</id>
    <updated>2018-08-27T06:32:46Z</updated>
    <published>2018-08-27T06:32:46Z</published>
    <summary type="html">&lt;p&gt;Hi All,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I am developing an app with Liferay web screenlet for rendering web
  pages in Android app. Now If I have to implement push notification in
  this app. How can I register device for users?&lt;/p&gt;
&lt;p&gt;For other screenlets, I did device registration after Login using
  LoginListener. How can I do the same in WebScreenlet?&lt;/p&gt;
&lt;p&gt;I want device to be registered, once user logged in portal using Web screenlet.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;br /&gt; Ankit&lt;/p&gt;</summary>
    <dc:creator>Ankit Srivastava</dc:creator>
    <dc:date>2018-08-27T06:32:46Z</dc:date>
  </entry>
</feed>
