下面列出了android.content.IntentSender#SendIntentException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Called when the Load Hints button is clicked. Requests a Credential "hint" which will
* be the basic profile information and an ID token for an account on the device. This is useful
* to auto-fill sign-up forms with an email address, picture, and name or to do password-free
* authentication with a server by providing an ID Token.
*/
private void loadHintClicked() {
HintRequest hintRequest = new HintRequest.Builder()
.setHintPickerConfig(new CredentialPickerConfig.Builder()
.setShowCancelButton(true)
.build())
.setIdTokenRequested(shouldRequestIdToken())
.setEmailAddressIdentifierSupported(true)
.setAccountTypes(IdentityProviders.GOOGLE)
.build();
;
PendingIntent intent = mCredentialsClient.getHintPickerIntent(hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
mIsResolving = true;
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Could not start hint picker Intent", e);
mIsResolving = false;
}
}
@Override
public void startIntentSender(IntentSender intent, Intent fillInIntent,
int flagsMask, int flagsValues, int extraFlags, Bundle options)
throws IntentSender.SendIntentException {
try {
String resolvedType = null;
if (fillInIntent != null) {
fillInIntent.migrateExtraStreamToClipData();
fillInIntent.prepareToLeaveProcess(this);
resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver());
}
int result = ActivityManager.getService()
.startActivityIntentSender(mMainThread.getApplicationThread(),
intent != null ? intent.getTarget() : null,
intent != null ? intent.getWhitelistToken() : null,
fillInIntent, resolvedType, null, null,
0, flagsMask, flagsValues, options);
if (result == ActivityManager.START_CANCELED) {
throw new IntentSender.SendIntentException();
}
Instrumentation.checkStartActivityResult(result, null);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public void startIntentSender(IntentSender intent, Intent fillInIntent,
int flagsMask, int flagsValues, int extraFlags, Bundle options)
throws IntentSender.SendIntentException {
try {
String resolvedType = null;
if (fillInIntent != null) {
fillInIntent.setAllowFds(false);
resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver());
}
int result = ActivityManagerNative.getDefault()
.startActivityIntentSender(mMainThread.getApplicationThread(), intent,
fillInIntent, resolvedType, null, null,
0, flagsMask, flagsValues, options);
if (result == ActivityManager.START_CANCELED) {
throw new IntentSender.SendIntentException();
}
Instrumentation.checkStartActivityResult(result, null);
} catch (RemoteException e) {
}
}
@Override
public void startIntentSender(IntentSender intent,
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
throws IntentSender.SendIntentException {
try {
String resolvedType = null;
if (fillInIntent != null) {
fillInIntent.setAllowFds(false);
resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver());
}
int result = ActivityManagerNative.getDefault()
.startActivityIntentSender(mMainThread.getApplicationThread(), intent,
fillInIntent, resolvedType, null, null,
0, flagsMask, flagsValues);
if (result == IActivityManager.START_CANCELED) {
throw new IntentSender.SendIntentException();
}
Instrumentation.checkStartActivityResult(result, null);
} catch (RemoteException e) {
}
}
@Override
public void onResult(@NonNull CredentialRequestResult credentialRequestResult) {
Status status = credentialRequestResult.getStatus();
if (status.isSuccess()) {
onCredentialRetrieved(credentialRequestResult.getCredential());
} else {
if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
try {
isResolving = true;
status.startResolutionForResult(this, RC_READ);
} catch (IntentSender.SendIntentException e) {
Log.d(TAG, e.toString());
}
} else {
showHintDialog();
}
}
}
@Test
public void purchaseFailsIfSignatureIsInvalid() throws RemoteException, IntentSender.SendIntentException {
mockDependeniesForSuccessfulPurchaseFlow();
InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, TEST_PUBLIC_KEY);
vendor.initialize(mock(Context.class), initializationListener);
Product inappPurchase = Product
.create(
InAppBillingConstants.VENDOR_PACKAGE,
"so.product.much.purchase",
"1",
"1",
"1",
"1",
false,
1);
PurchaseListener purchaseListener = mock(PurchaseListener.class);
vendor.purchase(activity, inappPurchase, "hello-cashier!", purchaseListener);
vendor.onActivityResult(
vendor.getRequestCode(),
Activity.RESULT_OK,
new Intent()
.putExtra(RESPONSE_CODE, BILLING_RESPONSE_RESULT_OK)
.putExtra(RESPONSE_INAPP_PURCHASE_DATA, VALID_PURCHASE_RECEIPT_JSON)
.putExtra(RESPONSE_INAPP_SIGNATURE, TEST_INVALID_PUBLIC_KEY));
verify(purchaseListener, times(1)).failure(inappPurchase, new Vendor.Error(PURCHASE_SUCCESS_RESULT_MALFORMED, BILLING_RESPONSE_RESULT_ERROR));
}
@Override public void startResolutionForLocation(ResolvableApiException resolvable) {
try {
resolvable.startResolutionForResult((Activity) context, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
private void resolveSignInError() {
if (mSignInIntent != null) {
try {
mSignInProgress = STATE_IN_PROGRESS;
startIntentSenderForResult(mSignInIntent.getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
mSignInProgress = STATE_SIGNING_IN;
mGoogleApiClient.connect();
}
} else {
// You have a Play Services error -- inform the user
}
}
public void triggerRecipientSelection(int requestCode, Intent actionIntent) {
PendingIntent pi = getGpgEncryptionHandler(getMView().getContext()).triggerRecipientSelection(actionIntent);
if (pi != null) {
try {
getActivity().startIntentSenderForResult(pi.getIntentSender(), requestCode, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
//TODO now what?
}
} else {
//TODO really needed? recipientsSelectedCallback.onRecipientsSelected(null);
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if( !authInProgress ) {
try {
authInProgress = true;
connectionResult.startResolutionForResult( MainActivity.this, REQUEST_OAUTH );
} catch(IntentSender.SendIntentException e ) {
Log.e( "GoogleFit", "sendingIntentException " + e.getMessage() );
}
} else {
Log.e( "GoogleFit", "authInProgress" );
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
/*
* Google Play services can resolve some errors it detects.
* If the error has a resolution, try sending an Intent to
* start a Google Play services activity that can resolve
* error.
*/
if (connectionResult.hasResolution()) {
try {
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST);
/*
* Thrown if Google Play services canceled the original
* PendingIntent
*/
} catch (IntentSender.SendIntentException e) {
// Log the error
e.printStackTrace();
}
} else {
/*
* If no resolution is available, display a dialog to the
* user with the error.
*/
Log.i(TAG, "Location services connection failed with code " + connectionResult.getErrorCode());
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult result) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (IntentSender.SendIntentException ignore) {
// The intent was canceled before it was sent.
}
}
}
private void startBuyIntent(final Activity activity,
final PendingIntent pendingIntent,
int requestCode) throws BillingException {
IntentSender sender = pendingIntent.getIntentSender();
try {
activity.startIntentSenderForResult(sender, requestCode, new Intent(), 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
throw new BillingException(Constants.ERROR_SEND_INTENT_FAILED, e.getMessage());
}
}
@Test
public void purchaseFailsIfResponseCodeIsInvalid() throws RemoteException, IntentSender.SendIntentException, JSONException {
mockDependeniesForSuccessfulPurchaseFlow();
InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, null);
vendor.initialize(mock(Context.class), initializationListener);
Product inappPurchase = Product
.create(
InAppBillingConstants.VENDOR_PACKAGE,
"so.product.much.purchase",
"1",
"1",
"1",
"1",
false,
1);
PurchaseListener purchaseListener = mock(PurchaseListener.class);
vendor.purchase(activity, inappPurchase, null, purchaseListener);
Intent intent = new Intent()
.putExtra(RESPONSE_CODE, BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE)
.putExtra(RESPONSE_INAPP_PURCHASE_DATA, VALID_PURCHASE_RECEIPT_JSON)
.putExtra(RESPONSE_INAPP_SIGNATURE, "");
vendor.onActivityResult(
vendor.getRequestCode(),
Activity.RESULT_OK,
intent);
verify(purchaseListener, times(1)).failure(inappPurchase, new Vendor.Error(PURCHASE_UNAVAILABLE, BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE));
}
private void startUpdate(AppUpdateInfo appUpdateInfo) {
try {
Log.d(TAG, "Starting update");
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
mode,
getActivity(),
UpdateManagerConstant.REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
Log.d(TAG, "" + e.getMessage());
}
}
@DebugLog
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(getActivity(),
RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
GooglePlayServicesUtil
.getErrorDialog(connectionResult.getErrorCode(), getActivity(), 0).show();
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult)
{
/*
* Google Play services can resolve some errors it detects.
* If the error has a resolution, try sending an Intent to
* start a Google Play services activity that can resolve
* error.
*/
if (connectionResult.hasResolution())
{
try
{
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(this, LocationUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST);
/*
* Thrown if Google Play services canceled the original
* PendingIntent
*/
} catch (IntentSender.SendIntentException e)
{
// Log the error
}
} else
{
// If no resolution is available, display a dialog to the user with the error.
//Log.e(LocationUtils.APPTAG, String.valueOf(connectionResult.getErrorCode()));
}
}
@Override
public void startIntentSender(IntentSender intent,
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
throws IntentSender.SendIntentException {
startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null);
}
@Override
public void startIntentSender(IntentSender intent,
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
throws IntentSender.SendIntentException {
startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null);
}
@TargetApi(16)
@Override
public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)
throws IntentSender.SendIntentException {
activity.startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, options);
}