本文整理汇总了Java中com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN属性的典型用法代码示例。如果您正苦于以下问题:Java AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN属性的具体用法?Java AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN怎么用?Java AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.AuthTokenConstants
的用法示例。
在下文中一共展示了AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestAuthTokenForMessage
/**
* Requests an auth token from the application to use to send {@code message} to the data
* center.
* <p>
* If not {@code null}, {@code invalidAuthToken} is an auth token that was previously
* found to be invalid. The intent sent to the application to request the new token will include
* the invalid token so that the application can invalidate it in the {@code AccountManager}.
*/
private void requestAuthTokenForMessage(byte[] message, String invalidAuthToken) {
/*
* Send an intent requesting an auth token. This intent will contain a pending intent
* that the recipient can use to send back the token (by attaching the token as a string
* extra). That pending intent will also contain the message that we were just asked to send,
* so that it will be echoed back to us with the token. This avoids our having to persist
* the message while waiting for the token.
*/
// This is the intent that the application will send back to us (the pending intent allows
// it to send the intent). It contains the stored message. We require that it be delivered to
// this class only, as a security check.
Intent tokenResponseIntent = new Intent(this, getClass());
tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE, message);
// If we have an invalid auth token, set a bit in the intent that the application will send
// back to us. This will let us know that it is a retry; if sending subsequently fails again,
// we will not do any further retries.
tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_IS_RETRY, invalidAuthToken != null);
// The pending intent allows the application to send us the tokenResponseIntent.
PendingIntent pendingIntent = PendingIntent.getService(
this, message.hashCode(), tokenResponseIntent, PendingIntent.FLAG_ONE_SHOT);
// We send the pending intent as an extra in a normal intent to the application. We require that
// the intent be delivered only within this package, as a security check. The application must
// define a service with an intent filter that matches the ACTION_REQUEST_AUTH_TOKEN in order
// to receive this intent.
Intent requestTokenIntent = new Intent(AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN);
requestTokenIntent.setPackage(getPackageName());
requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_PENDING_INTENT, pendingIntent);
if (invalidAuthToken != null) {
requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN, invalidAuthToken);
}
startService(requestTokenIntent);
}
示例2: requestAuthTokenForMessage
/**
* Requests an auth token from the application to use to send {@code message} to the data
* center.
* <p>
* If not {@code null}, {@code invalidAuthToken} is an auth token that was previously
* found to be invalid. The intent sent to the application to request the new token will include
* the invalid token so that the application can invalidate it in the {@code AccountManager}.
*/
private void requestAuthTokenForMessage(byte[] message, String invalidAuthToken) {
/*
* Send an intent requesting an auth token. This intent will contain a pending intent
* that the recipient can use to send back the token (by attaching the token as a string
* extra). That pending intent will also contain the message that we were just asked to send,
* so that it will be echoed back to us with the token. This avoids our having to persist
* the message while waiting for the token.
*/
// This is the intent that the application will send back to us (the pending intent allows
// it to send the intent). It contains the stored message. We require that it be delivered to
// this class only, as a security check.
Intent tokenResponseIntent = new Intent(this, getClass());
tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_STORED_MESSAGE, message);
// If we have an invalid auth token, set a bit in the intent that the application will send
// back to us. This will let us know that it is a retry; if sending subsequently fails again,
// we will not do any further retries.
tokenResponseIntent.putExtra(AuthTokenConstants.EXTRA_IS_RETRY, invalidAuthToken != null);
// The pending intent allows the application to send us the tokenResponseIntent.
PendingIntent pendingIntent = PendingIntent.getService(
this, Arrays.hashCode(message), tokenResponseIntent, PendingIntent.FLAG_ONE_SHOT);
// We send the pending intent as an extra in a normal intent to the application. The
// invalidation listener service must handle AUTH_TOKEN_REQUEST intents.
Intent requestTokenIntent = new Intent(AuthTokenConstants.ACTION_REQUEST_AUTH_TOKEN);
requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_PENDING_INTENT, pendingIntent);
if (invalidAuthToken != null) {
requestTokenIntent.putExtra(AuthTokenConstants.EXTRA_INVALIDATE_AUTH_TOKEN, invalidAuthToken);
}
String simpleListenerClass =
new AndroidTiclManifest(getApplicationContext()).getListenerServiceClass();
requestTokenIntent.setClassName(getApplicationContext(), simpleListenerClass);
try {
startService(requestTokenIntent);
} catch (SecurityException | IllegalStateException exception) {
logger.warning("unable to request auth token: %s", exception);
}
}