本文整理汇总了Java中com.google.android.gms.auth.api.credentials.Credential类的典型用法代码示例。如果您正苦于以下问题:Java Credential类的具体用法?Java Credential怎么用?Java Credential使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Credential类属于com.google.android.gms.auth.api.credentials包,在下文中一共展示了Credential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);
if (requestCode == RC_READ) {
if (resultCode == RESULT_OK) {
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
processRetrievedCredential(credential);
} else {
Log.e(TAG, "Credential Read: NOT OK");
setSignInEnabled(true);
}
} else if (requestCode == RC_SAVE) {
Log.d(TAG, "Result code: " + resultCode);
if (resultCode == RESULT_OK) {
Log.d(TAG, "Credential Save: OK");
} else {
Log.e(TAG, "Credential Save Failed");
}
goToContent();
}
mIsResolving = false;
}
示例2: saveCredential
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
protected void saveCredential(Credential credential) {
// Credential is valid so save it.
Auth.CredentialsApi.save(mGoogleApiClient,
credential).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "Credential saved");
goToContent();
} else {
Log.d(TAG, "Attempt to save credential failed " +
status.getStatusMessage() + " " +
status.getStatusCode());
resolveResult(status, RC_SAVE);
}
}
});
}
示例3: onActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
case GoogleApiAdapter.GOOGLE_SIGN_IN:
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
break;
case GoogleApiAdapter.REGISTER_CREDENTIAL:
login();
break;
case GoogleApiAdapter.RETRIEVE_CREDENTIALS:
if (resultCode == RESULT_OK) {
onCredentialRetrieved((Credential) data.getParcelableExtra(Credential.EXTRA_KEY));
}
break;
case REQUEST_PERMISSION:
refreshGCMToken();
break;
}
}
示例4: onCredentialRetrieved
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
void onCredentialRetrieved(Credential credential) {
if (IdentityProviders.GOOGLE.equals(credential.getAccountType())) {
final GoogleSignInResult result = googleApi.performSilentSignIn().get();
if (result.isSuccess()) {
createGoogleAccount(result.getSignInAccount());
} else if (result.getStatus().hasResolution()) {
try {
result.getStatus().startResolutionForResult(this, GoogleApiAdapter.GOOGLE_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
Snackbar.make(vLoginForm, R.string.error_smartlock_failed, Snackbar.LENGTH_LONG);
}
}
} else {
etUsername.setText(credential.getId());
etPassword.setText(credential.getPassword());
attemptLogin();
}
}
示例5: handleActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_READ) {
if (resultCode == Activity.RESULT_OK && data != null) {
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
getListener().onCredentialRetrieved(credential);
} else {
getListener().onCredentialRetrievalFailed();
}
return true;
}
if (requestCode == RC_SAVE) {
if (resultCode == Activity.RESULT_OK) {
Log.d(TAG, "RC_SAVE: Ok");
} else {
Log.d(TAG, "RC_SAVE: Failure");
}
return true;
}
return false;
}
示例6: getCredentials
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
/**
* Begin the process of retrieving a {@link Credential} for the device user. This can have
* a few different results:
* 1) If the user has auto sign-in enabled and exactly one previously saved credential,
* {@link SmartLockListener#onCredentialRetrieved(Credential)} will be called and
* you can sign the user in immediately.
* 2) If the user has multiple saved credentials or one saved credential and has disabled
* auto sign-in, you will get the callback {@link SmartLockListener#onShouldShowCredentialPicker()}
* at which point you can choose to show the picker dialog to continue.
* 3) If the user has no saved credentials or cancels the operation, you will receive the
* {@link SmartLockListener#onCredentialRetrievalFailed()} callback.
*/
public void getCredentials() {
CredentialRequest request = buildCredentialRequest();
Auth.CredentialsApi.request(getFragment().getGoogleApiClient(), request)
.setResultCallback(new ResultCallback<CredentialRequestResult>() {
@Override
public void onResult(CredentialRequestResult result) {
if (result.getStatus().isSuccess()) {
// Single credential, auto sign-in
Credential credential = result.getCredential();
getListener().onCredentialRetrieved(credential);
} else if (result.getStatus().hasResolution() &&
result.getStatus().getStatusCode() != CommonStatusCodes.SIGN_IN_REQUIRED) {
// Multiple credentials or auto-sign in disabled. If the status
// code is SIGN_IN_REQUIRED then it is a hint credential, which we
// do not want at this point.
getListener().onShouldShowCredentialPicker();
} else {
// Could not retrieve credentials
getListener().onCredentialRetrievalFailed();
}
}
});
}
示例7: getCredentialsFromFirebaseUser
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
/**
* Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
* for saving since we don't have access to the password.
*/
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
return Collections.emptyList();
}
List<Credential> credentials = new ArrayList<>();
for (UserInfo userInfo : user.getProviderData()) {
if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
continue;
}
String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
credentials.add(new Credential.Builder(
user.getEmail() == null ? user.getPhoneNumber() : user.getEmail())
.setAccountType(type)
.build());
}
return credentials;
}
示例8: onActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RC_HINT:
if (data != null) {
mLastCredential = data.getParcelableExtra(Credential.EXTRA_KEY);
if (mLastCredential != null) {
// Get the email from the credential
mEmailEditText.setText(mLastCredential.getId());
// Attempt to proceed
validateAndProceed();
}
}
break;
case RC_SIGN_IN:
case RC_WELCOME_BACK_IDP:
finish(resultCode, data);
break;
}
}
示例9: onActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SAVE) {
if (resultCode != Activity.RESULT_OK) {
Log.e(TAG, "SAVE: Canceled by user");
}
finish();
} else if (requestCode == RC_UPDATE_SERVICE) {
if (resultCode == Activity.RESULT_OK) {
Credential credential = new Credential.Builder(mEmail).setPassword(mPassword)
.build();
getAuthHelper().getCredentialsApi()
.save(mGoogleApiClient, credential)
.setResultCallback(this);
} else {
Log.e(TAG, "SAVE: Canceled by user");
finish();
}
}
}
示例10: onConnected
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
void onConnected(final SmartLock smartLock, final Activity activity) {
Log.v(TAG, "Requesting credentials from SmartLock");
getCredentialsApi().request(smartLock.getCredentialClient(), smartLock.newCredentialRequest()).setResultCallback(new ResultCallback<CredentialRequestResult>() {
@Override
public void onResult(CredentialRequestResult credentialRequestResult) {
final com.google.android.gms.common.api.Status status = credentialRequestResult.getStatus();
if (status.isSuccess()) {
final Credential credential = credentialRequestResult.getCredential();
Log.v(TAG, "Retrieved credentials for type " + credential.getAccountType());
smartLock.onCredentialsRetrieved(activity, credential);
} else {
smartLock.onCredentialRetrievalError(activity, status, SmartLock.SMART_LOCK_READ);
}
}
});
}
示例11: onActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
/**
* Method called in {@link Activity#onActivityResult(int, int, Intent)} callback to handle SmartLock interaction
* @param activity that received the result
* @param requestCode of the request
* @param resultCode received by the activity
* @param data of the result
*/
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case SMART_LOCK_READ:
if (resultCode == Activity.RESULT_OK) {
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
onCredentialsRetrieved(activity, credential);
} else {
startLockFromActivity(activity);
}
break;
case SMART_LOCK_SAVE:
final CredentialStoreCallback callback = getCallback();
if (resultCode == Activity.RESULT_OK) {
callback.onSuccess();
} else {
callback.onError(CredentialStoreCallback.CREDENTIAL_STORE_SAVE_CANCELLED, null);
}
clearCredentialStoreCallback();
break;
}
}
示例12: saveFromActivity
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
/**
* Saves the user's credentials in Smart Lock for Android
* @param activity that wants to save the credentials
* @param username of the used to login
* @param email of the user
* @param password of the used to login
* @param pictureUrl of the user
* @param callback that will be called when the operation is completed
*/
@Override
public void saveFromActivity(Activity activity, String username, String email, String password, String pictureUrl, CredentialStoreCallback callback) {
if ((username == null && email == null) || password == null) {
Log.w(TAG, "Invalid credentials to save in Smart Lock");
callback.onError(CredentialStoreCallback.CREDENTIAL_STORE_SAVE_FAILED, null);
clearCredentialStoreCallback();
return;
}
setCallback(callback);
String id = email != null ? email : username;
Uri pictureUri = pictureUrl != null ? Uri.parse(pictureUrl) : null;
final Credential credential = new Credential.Builder(id)
.setName(username)
.setProfilePictureUri(pictureUri)
.setPassword(password)
.build();
startTask(new SaveCredentialTask(activity, credential));
}
示例13: onCredentialsRetrieved
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
void onCredentialsRetrieved(final Activity activity, final Credential credential) {
Log.v(TAG, "Credentials : " + credential.getName());
String email = credential.getId();
String password = credential.getPassword();
getAPIClient().login(email, password, getAuthenticationParameters(), new AuthenticationCallback() {
@Override
public void onSuccess(UserProfile profile, Token token) {
Intent result = new Intent(Lock.AUTHENTICATION_ACTION)
.putExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER, profile)
.putExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER, token);
LocalBroadcastManager.getInstance(activity).sendBroadcast(result);
}
@Override
public void onFailure(Throwable throwable) {
LoginAuthenticationErrorBuilder builder = new LoginAuthenticationErrorBuilder();
AuthenticationError error = builder.buildFrom(throwable);
ErrorDialogBuilder.showAlertDialog(activity, error);
}
});
}
示例14: onActivityResult
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CREDENTIAL_REQUEST_RC) {
if (resultCode == RESULT_OK) {
mSmartLock.retrieveCredentialFromIntent(data).subscribe(new Action1<Credential>() {
@Override
public void call(Credential credential) {
onSuccess(credential);
}
});
} else {
Log.e(TAG, "Credential Read: NOT OK");
}
}
}
示例15: call
import com.google.android.gms.auth.api.credentials.Credential; //导入依赖的package包/类
@Override
public void call(Subscriber<? super Credential> subscriber) {
final GoogleApiClient googleApiClient = buildGoogleApiClient(subscriber);
try {
googleApiClient.connect();
} catch (Exception e) {
subscriber.onError(e);
}
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (googleApiClient.isConnected() || googleApiClient.isConnecting()) {
googleApiClient.disconnect();
}
}
}));
}