public class

LoginButton

extends AppCompatTextView
java.lang.Object
   ↳ AppCompatTextView
     ↳ com.linecorp.linesdk.widget.LoginButton

Class Overview

A button widget that simplifies the login flow. Before you add login listeners to this login button through the addLoginListener(LoginListener) method, set your channel ID through the setChannelId(String) method and login delegate through the setLoginDelegate(LoginDelegate) method. Otherwise, a RuntimeException is thrown. Also, use the provided create() method to create a LoginDelegate instance and set it to this button through the setLoginDelegate(LoginDelegate) method.

By default, this button performs the login process using LINE with the PROFILE scope only. You can create your own LineAuthenticationParams instance using the provided LineAuthenticationParams.Builder method and set the authentication parameters to this button through the setAuthenticationParams(LineAuthenticationParams) method. You can also control whether the user logs in with LINE or with the browser through the enableLineAppAuthentication(boolean) method.

Finally, call the onActivityResult(int, int, Intent) method using the intent that you created with the Activity#onActivityResult(int, int, Intent) method. If you use this button in a Fragment or an androidx.fragment.app.Fragment instance, set the fragment to this button through the setFragment(Fragment) method or the setFragment(androidx.fragment.app.Fragment) method. By doing so, you can call the onActivityResult callback in your fragment after the login process is complete.

The following example shows how to set up the login button with the desired parameters.

 int loginButtonResId = ...;
 String channelId = ...;
 LoginDelegate loginDelegate = LoginDelegate.Factory.create();
 LineAuthenticationParams params = LineAuthenticationParams.Builder()
                                         .scopes(...)
                                         .nonce(...)
                                         .botPrompt(...)
                                         .build();

 LoginButton loginButton = findViewById(loginButtonResId);
 loginButton.setChannelId(channelId);
 loginButton.setLoginDelegate(loginDelegate);
 loginButton.enableLineAppAuthentication(true);
 loginButton.setAuthenticationParams(params);
 loginButton.addLoginListener(new LoginListener() {
    @Override
     public void onLoginSuccess(@NonNull LineLoginResult result) {
         ...
     }

    @Override
     public void onLoginFailure(@Nullable LineLoginResult result) {
     if (result != null) {
         ...
     } else {
         ...
     }
 });
 
The example below handles the login result intent in the onActivityResult method.
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     if (loginDelegate.onActivityResult(requestCode, resultCode, data)) {
         // login result intent is consumed.
         return;
     }
 }
 

Summary

Public Constructors
LoginButton(Context context)
LoginButton(Context context, AttributeSet attrs)
LoginButton(Context context, AttributeSet attrs, int defStyleAttr)
Public Methods
void addLoginListener(LoginListener loginListener)
Sets the given loginListener to listen to the login result.
void enableLineAppAuthentication(boolean isEnabled)
Sets whether the user logs in with LINE or with the browser according to the given isEnabled parameter.
void removeLoginListener(LoginListener loginListener)
Removes the given loginListener and stops it from listening to the login result.
void setAuthenticationParams(LineAuthenticationParams params)
Sets the authentication parameters that you want your application to use when it performs a login.
void setChannelId(String channelId)
Sets the channel ID of the channel that your application your application will use to log in.
void setFragment(Fragment fragment)
Specifies the fragment that contains this button so that its android.app.Fragment.onActivityResult(int, int, Intent) method is properly called.
void setFragment(androidx.fragment.app.Fragment fragment)
Specifies the fragment that contains this button so that its androidx.fragment.app.Fragment#onActivityResult(int, int, Intent) method is properly called.
void setLoginDelegate(LoginDelegate loginDelegate)
Sets the login delegate.
void setOnClickListener(OnClickListener externalListener)
Registers a callback to be invoked when this button is tapped.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public LoginButton (Context context)

public LoginButton (Context context, AttributeSet attrs)

public LoginButton (Context context, AttributeSet attrs, int defStyleAttr)

Public Methods

public void addLoginListener (LoginListener loginListener)

Sets the given loginListener to listen to the login result.

Parameters
loginListener The listener to set to listen to the login result.

public void enableLineAppAuthentication (boolean isEnabled)

Sets whether the user logs in with LINE or with the browser according to the given isEnabled parameter.

Parameters
isEnabled True if you want the user to log in with LINE instead of the browser; false otherwise. The default value is true.

public void removeLoginListener (LoginListener loginListener)

Removes the given loginListener and stops it from listening to the login result.

Parameters
loginListener The listener to be removed.

public void setAuthenticationParams (LineAuthenticationParams params)

Sets the authentication parameters that you want your application to use when it performs a login.

Parameters
params The authentication parameters.

public void setChannelId (String channelId)

Sets the channel ID of the channel that your application your application will use to log in.

Parameters
channelId The channel ID.

public void setFragment (Fragment fragment)

Specifies the fragment that contains this button so that its android.app.Fragment.onActivityResult(int, int, Intent) method is properly called.

Parameters
fragment The Fragment that contains this button.

public void setFragment (androidx.fragment.app.Fragment fragment)

Specifies the fragment that contains this button so that its androidx.fragment.app.Fragment#onActivityResult(int, int, Intent) method is properly called.

Parameters
fragment The androidx.fragment.app.Fragment that contains this button.

public void setLoginDelegate (LoginDelegate loginDelegate)

Sets the login delegate. This should be created using the create() method. If the delegate is not set, a RuntimeException is thrown. You also must call the onActivityResult(int, int, Intent) method of the given loginDelegate in the Activity or Fragment instance to handle the response intent.

public void setOnClickListener (OnClickListener externalListener)

Registers a callback to be invoked when this button is tapped.

Parameters
externalListener The callback to be invoked. This value may be null.