android.content.IntentSender Java Examples

The following examples show how to use android.content.IntentSender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@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();
            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) {
    }
}
 
Example #2
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #3
Source File: WearService.java    From LibreAlarm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (result.hasResolution() && mActivity != null) {
        try {
            mResolvingError = true;
            result.startResolutionForResult(mActivity, 1000);
        } catch (IntentSender.SendIntentException e) {
            // There was an error with the resolution intent. Try again.
            mGoogleApiClient.connect();
        }
    } else {
        Log.e(TAG, "Connection to Google API client has failed");
        mResolvingError = false;
        if (mListener != null) mListener.onDataUpdated();
        Wearable.MessageApi.removeListener(mGoogleApiClient, this);
        Wearable.DataApi.removeListener(mGoogleApiClient, this);
    }
}
 
Example #4
Source File: InAppBillingV3VendorTest.java    From Cashier with Apache License 2.0 6 votes vote down vote up
@Test
public void purchaseFailsIfResultIntentIsNull() throws RemoteException, IntentSender.SendIntentException {
    mockDependeniesForSuccessfulPurchaseFlow();

    InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, null);
    vendor.initialize(mock(Context.class), initializationListener);

    Product inappPurchase = Product
            .create(
                    InAppBillingConstants.VENDOR_PACKAGE,
                    "1",
                    "1",
                    "1",
                    "1",
                    "1",
                    false,
                    1);

    PurchaseListener purchaseListener = mock(PurchaseListener.class);
    vendor.purchase(activity, inappPurchase, null, purchaseListener);
    vendor.onActivityResult(vendor.getRequestCode(), Activity.RESULT_OK, null);
    verify(purchaseListener, times(1)).failure(inappPurchase, new Vendor.Error(PURCHASE_FAILURE, BILLING_RESPONSE_RESULT_ERROR));
}
 
Example #5
Source File: BeaconsFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleUnsuccessfulNearbyResult(Status status) {
    Log.v(TAG, "Processing error, status = " + status);
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (status.hasResolution()) {
        try {
            mResolvingError = true;
            status.startResolutionForResult(getActivity(),
                    REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            mResolvingError = false;
            Log.v(TAG, "Failed to resolve error status.", e);
        }
    } else {
        if (status.getStatusCode() == CommonStatusCodes.NETWORK_ERROR) {
            Toast.makeText(getActivity(),
                    "No connectivity, cannot proceed. Fix in 'Settings' and try again.",
                    Toast.LENGTH_LONG).show();
        } else {
            // To keep things simple, pop a toast for all other error messages.
            Toast.makeText(getActivity(), "Unsuccessful: " +
                    status.getStatusMessage(), Toast.LENGTH_LONG).show();
        }
    }
}
 
Example #6
Source File: BaseActivity.java    From attendee-checkin with Apache License 2.0 6 votes vote down vote up
private void signIn() {
    if (mApiClient.isConnected()) {
        return;
    }
    if (mConnectionResult == null) {
        mConnectionProgressDialog.show();
    } else {
        try {
            mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            // Retry connecting
            mConnectionResult = null;
            mApiClient.connect();
        }
    }
}
 
Example #7
Source File: VPackageInstallerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void uninstall(String packageName, String callerPackageName, int flags, IntentSender statusReceiver, int userId) throws RemoteException {
    boolean success = VAppManagerService.get().uninstallApp(packageName);
    if (statusReceiver != null) {
        final Intent fillIn = new Intent();
        fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, packageName);
        fillIn.putExtra(PackageInstaller.EXTRA_STATUS, success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE);
        fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageHelper.deleteStatusToString(success));
        fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", success ? 1 : -1);
        try {
            statusReceiver.sendIntent(mContext, 0, fillIn, null, null);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    }
}
 
Example #8
Source File: PhoneNumberActivity.java    From android-credentials with Apache License 2.0 6 votes vote down vote up
private void showHint() {
    ui.clearKeyboard();
    HintRequest hintRequest = new HintRequest.Builder()
            .setHintPickerConfig(new CredentialPickerConfig.Builder()
                    .setShowCancelButton(true)
                    .build())
            .setPhoneNumberIdentifierSupported(true)
            .build();

    PendingIntent intent =
            Auth.CredentialsApi.getHintPickerIntent(mCredentialsApiClient, hintRequest);
    try {
        startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.e(TAG, "Could not start hint picker Intent", e);
    }
}
 
Example #9
Source File: VPackageInstallerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPackageInstalled(String basePackageName, int returnCode, String msg,
                               Bundle extras) {
    final Intent fillIn = new Intent();
    fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, basePackageName);
    fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID, mSessionId);
    fillIn.putExtra(PackageInstaller.EXTRA_STATUS,
            installStatusToPublicStatus(returnCode));
    fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE,
            installStatusToString(returnCode, msg));
    fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", returnCode);
    if (extras != null) {
        final String existing = extras.getString("android.content.pm.extra.FAILURE_EXISTING_PACKAGE");
        if (!TextUtils.isEmpty(existing)) {
            fillIn.putExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME, existing);
        }
    }
    try {
        mTarget.sendIntent(mContext, 0, fillIn, null, null);
    } catch (IntentSender.SendIntentException ignored) {
    }
}
 
Example #10
Source File: GpgEncryptionParamsFragment.java    From oversec with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void downloadKey(final long keyId, Intent actionIntent) {
    PendingIntent pi = getGpgEncryptionHandler(getMView().getContext()).getDownloadKeyPendingIntent(keyId, actionIntent);

    if (pi != null) {

        mTempDownloadKeyId = keyId;
        try {
            getActivity().startIntentSenderForResult(pi.getIntentSender(), EncryptionParamsActivityContract.REQUEST_CODE_DOWNLOAD_KEY, null, 0, 0, 0);

        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
            //TODO what now?
        }

    }

}
 
Example #11
Source File: Client.java    From godot-gpgs with MIT License 6 votes vote down vote up
public boolean resolveConnectionFailure(ConnectionResult result, int requestCode) {
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            googleApiClient.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();

        if (errorCode == ConnectionResult.INTERNAL_ERROR) {
            googleApiClient.connect();
        }

        GodotLib.calldeferred(instance_id, "_on_google_play_game_services_connection_failed", new Object[] { });
        Log.i(TAG, "GPGS: onConnectionFailed error code: " + String.valueOf(errorCode));
        return false;
    }
}
 
Example #12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@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) {
    }
}
 
Example #14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@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) {
    }
}
 
Example #15
Source File: LeanbackFragment.java    From CumulusTV with MIT License 6 votes vote down vote up
@Override
public void onResult(DriveApi.DriveContentsResult result) {
    MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
            .setTitle("cumulustv_channels.json")
            .setDescription("JSON list of channels that can be imported using CumulusTV to view live streams")
            .setMimeType("application/json").build();
    IntentSender intentSender = Drive.DriveApi
            .newCreateFileActivityBuilder()
            .setActivityTitle("cumulustv_channels.json")
            .setInitialMetadata(metadataChangeSet)
            .setInitialDriveContents(result.getDriveContents())
            .build(CloudStorageProvider.getInstance().getClient());
    try {
        mActivity.startIntentSenderForResult(
                intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.w(TAG, "Unable to send intent", e);
    }
}
 
Example #16
Source File: MainActivity.java    From android-credentials with Apache License 2.0 6 votes vote down vote up
/**
     * 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;
        }
    }
 
Example #17
Source File: ActivityUtils.java    From CumulusTV with MIT License 5 votes vote down vote up
public static void syncFile(Activity activity, GoogleApiClient gapi) {
    if (DEBUG) {
    Log.d(TAG, "About to sync a file");
    }
    if (gapi == null && mCloudStorageProvider.connect(activity) != null) {
        gapi = mCloudStorageProvider.connect(activity);
    } else if(mCloudStorageProvider.connect(activity) == null) {
        // Is not existent
        Toast.makeText(activity, "There is no Google Play Service", Toast.LENGTH_SHORT).show();
        return;
    }
    if (gapi.isConnected()) {
        IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                .setMimeType(new String[]{"application/json", "text/*"})
                .build(gapi);
        try {
            if (DEBUG) {
                Log.d(TAG, "About to start activity");
            }
            activity.startIntentSenderForResult(intentSender, REQUEST_CODE_OPENER, null, 0, 0,
                    0);
            if (DEBUG) {
                Log.d(TAG, "Activity activated");
            }
        } catch (IntentSender.SendIntentException e) {
            if (DEBUG) {
                Log.w(TAG, "Unable to send intent", e);
            }
            e.printStackTrace();
        }
    } else {
        Toast.makeText(activity, R.string.toast_msg_wait_google_api_client,
                Toast.LENGTH_SHORT).show();
    }
}
 
Example #18
Source File: BeaconsFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {

    Log.v(TAG, "GoogleApiClient failed");
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(getActivity(), REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    } else {
        Log.v(TAG, "GoogleApiClient connection failed");
        updateNearbyPermissionStatus(false);
    }
}
 
Example #19
Source File: UpdateManager.java    From InAppUpdater with MIT License 5 votes vote down vote up
private void continueUpdateForImmediate() {
    instance.appUpdateManager
            .getAppUpdateInfo()
            .addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
                @Override
                public void onSuccess(AppUpdateInfo appUpdateInfo) {
                    if (appUpdateInfo.updateAvailability()
                            == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                        // If an in-app update is already running, resume the update.
                        try {
                            instance.appUpdateManager.startUpdateFlowForResult(
                                    appUpdateInfo,
                                    instance.mode,
                                    getActivity(),
                                    UpdateManagerConstant.REQUEST_CODE);
                        } catch (IntentSender.SendIntentException e) {
                            Log.d(TAG, "" + e.getMessage());
                        }
                    }
                }
            });
}
 
Example #20
Source File: MainActivity.java    From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createLocationRequestForResult(){
    mLocationRequestBalancedPowerAccuracy = new LocationRequest();
    final LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequestBalancedPowerAccuracy)
            .setAlwaysShow(true);
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());

    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult locationSettingsResult) {
            Log.v("BLE", locationSettingsResult.getStatus().getStatusMessage());
            LocationSettingsStates states = locationSettingsResult.getLocationSettingsStates();
            if(states.isLocationUsable()) {
                checkForLocationPermissionsAndScan();
                return;
            }

            final Status status = locationSettingsResult.getStatus();
            switch(status.getStatusCode()){
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    mLocationServicesRequestApproved = false;
                    try {
                        status.startResolutionForResult(MainActivity.this, REQUEST_LOCATION_SERVICES);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SUCCESS:
                    mLocationServicesRequestApproved = true;
                    checkForLocationPermissionsAndScan();
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    showPermissionRationaleFragment(R.string.rationale_location_cancel_message, 0);
                    break;
            }
        }
    });
}
 
Example #21
Source File: ExploreFragment.java    From rox-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(getActivity(), GOOGLE_API_CLIENT_CONNECTION_FAILURE_RESOLUTION_REQUEST);
        } catch (IntentSender.SendIntentException ex) {
            Log.e(TAG, "Intent sender exception", ex);
        }
    } else {
        Log.i(TAG, "Location services connection failed with code " + connectionResult.getErrorCode());
    }
}
 
Example #22
Source File: GoogleOAuthActivity.java    From firebase-login-demo-android with MIT License 5 votes vote down vote up
private void resolveSignInError() {
    if (mGoogleConnectionResult.hasResolution()) {
        try {
            mGoogleIntentInProgress = true;
            mGoogleConnectionResult.startResolutionForResult(this, MainActivity.RC_GOOGLE_LOGIN);
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            mGoogleIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
}
 
Example #23
Source File: InstallActivity.java    From XAPKInstaller with Apache License 2.0 5 votes vote down vote up
@TargetApi(21)
private void commitSession(PackageInstaller.Session session) {

    // Create an install status receiver.

    Intent intent = new Intent(this, InstallActivity.class);
    intent.setAction(PACKAGE_INSTALLED_ACTION);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    IntentSender statusReceiver = pendingIntent.getIntentSender();

    // Commit the session (this will start the installation workflow).
    session.commit(statusReceiver);

}
 
Example #24
Source File: RxSmartLockPasswordsFragment.java    From RxSocialAuth with Apache License 2.0 5 votes vote down vote up
private void saveCredential() {
    Auth.CredentialsApi.save(mCredentialsApiClient, mCredential).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        // save options
                        SmartLockHelper.getInstance(mActivity).saveSmartLockOptions(mSmartLockOptions);
                        // credential saved
                        mCredentialsApiClient.disconnect();
                        mStatusSubject.onNext(new RxStatus(status));
                        mStatusSubject.onCompleted();
                    }
                    else if(status.hasResolution()) {
                        // Try to resolve the save request. This will prompt the user if
                        // the credential is new.
                        try {
                            status.startResolutionForResult(mActivity, RC_SAVE);
                        } catch (IntentSender.SendIntentException e) {
                            // Could not resolve the request
                            mCredentialsApiClient.disconnect();
                            mStatusSubject.onError(new Throwable(e.toString()));
                        }
                    }
                    else {
                        // request has no resolution
                        mCredentialsApiClient.disconnect();
                        mStatusSubject.onCompleted();
                    }
                }
            });
}
 
Example #25
Source File: Fragment.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int,
 * Bundle)} from the fragment's containing Activity.
 */
public void startIntentSenderForResult(IntentSender intent, int requestCode,
        @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
        Bundle options) throws IntentSender.SendIntentException {
    if (mHost == null) {
        throw new IllegalStateException("Fragment " + this + " not attached to Activity");
    }
    mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask,
            flagsValues, extraFlags, options);
}
 
Example #26
Source File: FlowUtils.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private static void startIntentSenderForResult(HelperActivityBase activity,
                                               PendingIntent intent,
                                               int requestCode) {
    try {
        activity.startIntentSenderForResult(
                intent.getIntentSender(), requestCode, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        activity.finish(Activity.RESULT_CANCELED, IdpResponse.getErrorIntent(e));
    }
}
 
Example #27
Source File: BaseGameUtils.java    From Onesearch with MIT License 5 votes vote down vote up
/**
 * Resolve a connection failure from
 * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
 *
 * @param activity the Activity trying to resolve the connection failure.
 * @param client the GoogleAPIClient instance of the Activity.
 * @param result the ConnectionResult received by the Activity.
 * @param requestCode a request code which the calling Activity can use to identify the result
 *                    of this resolution in onActivityResult.
 * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved.
 * @return true if the connection failure is resolved, false otherwise.
 */
public static boolean resolveConnectionFailure(Activity activity,
                                               GoogleApiClient client, ConnectionResult result, int requestCode,
                                               String fallbackErrorMessage) {

    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            client.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                activity, requestCode);
        if (dialog != null) {
            dialog.show();
        } else {
            // no built-in dialog: show the fallback error message
            showAlert(activity, fallbackErrorMessage);
        }
        return false;
    }
}
 
Example #28
Source File: LoginActivity.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
        } catch (IntentSender.SendIntentException e) {
            mPlusClient.connect();
        }
    }
    mConnectionResult = result;
}
 
Example #29
Source File: InstallerPrivilegedSession.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
private IntentSender getIntentSender(int sessionId) {
    return PendingIntent.getBroadcast(
        context,
        sessionId,
        new Intent(BROADCAST_ACTION_INSTALL),
        PendingIntent.FLAG_UPDATE_CURRENT
    ).getIntentSender();
}
 
Example #30
Source File: ShortcutRequestPinProcessor.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private PinShortcutRequestInner(ShortcutRequestPinProcessor processor,
        ShortcutInfo shortcutOriginal, ShortcutInfo shortcutForLauncher,
        IntentSender resultIntent,
        String launcherPackage, int launcherUserId, int launcherUid, boolean preExisting) {
    super(processor, resultIntent, launcherUid);
    this.shortcutOriginal = shortcutOriginal;
    this.shortcutForLauncher = shortcutForLauncher;
    this.launcherPackage = launcherPackage;
    this.launcherUserId = launcherUserId;
    this.preExisting = preExisting;
}