java.lang.Object | ||
↳ | AppCompatTextView | |
↳ | com.linecorp.linesdk.widget.LoginButton |
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; } }
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Sets the given loginListener to listen to the login result.
loginListener | The listener to set to listen to the login result. |
---|
Sets whether the user logs in with LINE or with the browser according to the given isEnabled parameter.
isEnabled | True if you want the user to log in with LINE instead of the browser; false otherwise. The default value is true. |
---|
Removes the given loginListener and stops it from listening to the login result.
loginListener | The listener to be removed. |
---|
Sets the authentication parameters that you want your application to use when it performs a login.
params | The authentication parameters. |
---|
Sets the channel ID of the channel that your application your application will use to log in.
channelId | The channel ID. |
---|
Specifies the fragment that contains this button so that its
android.app.Fragment.onActivityResult(int, int, Intent)
method is properly called.
fragment | The Fragment that contains this button. |
---|
Specifies the fragment that contains this button so that its
androidx.fragment.app.Fragment#onActivityResult(int, int, Intent)
method is properly called.
fragment | The androidx.fragment.app.Fragment that contains this button.
|
---|
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.
Registers a callback to be invoked when this button is tapped.
externalListener | The callback to be invoked. This value may be null. |
---|