public class LoginButton
extends java.lang.Object
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 LoginDelegate.Factory#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 Scope.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 LoginDelegate.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 Fragment
instance, set the fragment to this button through the setFragment(Fragment) method or
the #setFragment(android.support.v4.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;
}
}
| Constructor and Description |
|---|
LoginButton(Context context) |
LoginButton(Context context,
AttributeSet attrs) |
LoginButton(Context context,
AttributeSet attrs,
int defStyleAttr) |
| Modifier and Type | Method and Description |
|---|---|
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(java.lang.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
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.
|
public LoginButton(Context context)
public LoginButton(Context context,
AttributeSet attrs)
public LoginButton(Context context,
AttributeSet attrs,
int defStyleAttr)
public void setOnClickListener(@Nullable
OnClickListener externalListener)
externalListener - The callback to be invoked. This value may be null.public void setFragment(@NonNull
Fragment fragment)
Fragment#onActivityResult(int, int, Intent) method is properly called.fragment - The Fragment that contains this button.public void setLoginDelegate(@NonNull
LoginDelegate loginDelegate)
LoginDelegate.Factory#create()
method. If the delegate is not set, a RuntimeException is thrown.
You also must call the LoginDelegate.onActivityResult(int, int, Intent) method of
the given loginDelegate in the Activity or Fragment instance
to handle the response intent.public void addLoginListener(@NonNull
LoginListener loginListener)
loginListener - The listener to set to listen to the login result.public void removeLoginListener(@NonNull
LoginListener loginListener)
loginListener - The listener to be removed.public void enableLineAppAuthentication(boolean isEnabled)
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 setChannelId(@NonNull
java.lang.String channelId)
channelId - The channel ID.public void setAuthenticationParams(@NonNull
LineAuthenticationParams params)
params - The authentication parameters.