android.content.IntentSender.SendIntentException#com.google.android.gms.common.GooglePlayServicesUtil源码实例Demo

下面列出了android.content.IntentSender.SendIntentException#com.google.android.gms.common.GooglePlayServicesUtil 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SimplePomodoro-android   文件: TaskListFragment.java
/** Check that Google Play services APK is installed and up to date. */
	  private boolean checkGooglePlayServicesAvailable() {
//	    final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
//	    if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
//	      showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
//	      return false;
//	    }
	 // Check status of Google Play Services
	    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());

	    // Check Google Play Service Available
	    try {
	        if (status != ConnectionResult.SUCCESS) {
	            GooglePlayServicesUtil.getErrorDialog(status, getActivity(), status).show();
	        }
	    } catch (Exception e) {
	        Log.e("Error: GooglePlayServiceUtil: ", "" + e);
	    }
	    return true;
	  }
 
源代码2 项目: effective_android_sample   文件: MainActivity.java
protected boolean servicesConnected() {

        // Google Play Servicesが利用可能かどうかチェック
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        if (ConnectionResult.SUCCESS == resultCode) {
            // Google Play Servicesが利用可能な場合
            return true;
        } else {
            // Google Play Servicesが何らかの理由で利用できない場合

            // 解決策が書いてあるダイアログが貰えるので、DialogFragmentで表示する
            showErrorDialog(resultCode, 0);
            return false;
        }

    }
 
源代码3 项目: mytracks   文件: TrackListActivity.java
private void checkGooglePlayServices() {
  int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  if (code != ConnectionResult.SUCCESS) {
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
        code, this, GOOGLE_PLAY_SERVICES_REQUEST_CODE, new DialogInterface.OnCancelListener() {

            @Override
          public void onCancel(DialogInterface dialogInterface) {
            finish();
          }
        });
    if (dialog != null) {
      dialog.show();
      return;
    }
  }
}
 
源代码4 项目: android   文件: DataCastManager.java
/**
 * Initializes the DataCastManager for clients. Before clients can use DataCastManager, they
 * need to initialize it by calling this static method. Then clients can obtain an instance of
 * this singleton class by calling {@link DataCastManager#getInstance()}. Failing to initialize
 * this class before requesting an instance will result in a {@link CastException} exception.
 *
 * @param context
 * @param applicationId the unique ID for your application
 * @param namespaces to be set up for this class.
 * @return
 */
public static DataCastManager initialize(Context context,
        String applicationId, String... namespaces) {
    if (null == sInstance) {
        LOGD(TAG, "New instance of DataCastManager is created");
        if (ConnectionResult.SUCCESS != GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(context)) {
            String msg = "Couldn't find the appropriate version of Google Play Services";
            LOGE(TAG, msg);
            throw new RuntimeException(msg);
        }
        sInstance = new DataCastManager(context, applicationId, namespaces);
        mCastManager = sInstance;
    }
    return sInstance;
}
 
源代码5 项目: osmdroid   文件: MapFactory.java
/**
 * Check whether Google Maps v2 is supported on this device.
 */
public static boolean isGoogleMapsV2Supported(final Context aContext) {
	try {
		// first check if Google Play Services is available
		int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(aContext);
		if (resultCode == ConnectionResult.SUCCESS) {
			// then check if OpenGL ES 2.0 is available
			final ActivityManager activityManager =
					(ActivityManager) aContext.getSystemService(Context.ACTIVITY_SERVICE);
			final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
			return configurationInfo.reqGlEsVersion >= 0x20000;
		}
	} catch (Throwable e) {
	}
	return false;
}
 
源代码6 项目: drip-steps   文件: MainActivity.java
@Override
public void onConnectionFailed(ConnectionResult result) {
	if (!result.hasResolution()) {
		GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), MainActivity.this, 0).show();
		return;
	}

	if (!authInProgress) {
		try {
			authInProgress = true;
			result.startResolutionForResult(MainActivity.this, REQUEST_OAUTH);
		} catch (IntentSender.SendIntentException e) {
			Toast.makeText(MainActivity.this, R.string.connection_failed, Toast.LENGTH_LONG).show();
			finish();
		}
	}
}
 
@Override
public void onClick(View v) {
    switch (v.getId()) {

        case R.id.btn_open: {
            int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
            if(status != ConnectionResult.SUCCESS) {
                GooglePlayServicesUtil.getErrorDialog(status, this, status);
                showToast("Cannot run without Google Play, please check!");
            } else {
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
            }
            break;
        }
        default:
            break;
    }
}
 
/**
 * Checks if Google Play Services are installed and if not it initializes
 * opening the dialog to allow user to install Google Play Services.
 * @return a boolean indicating if the Google Play Services are available.
 */
private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
/**
 * Checks if Google Play Services are installed and if not it initializes
 * opening the dialog to allow user to install Google Play Services.
 * @return a boolean indicating if the Google Play Services are available.
 */
private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    MainActivity.PLAY_SERVICES_RESOLUTION_REQUEST).show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
源代码10 项目: effective_android_sample   文件: MainActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.action_lisence:

        final String message = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);

        new AlertDialog.Builder(this).setTitle(R.string.action_lisence).setMessage(message)
                .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();

        break;
    }

    return super.onOptionsItemSelected(item);
}
 
源代码11 项目: CumulusTV   文件: LeanbackFragment.java
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (DEBUG) {
        Log.d(TAG, "Error connecting " + connectionResult.getErrorCode());
        Log.d(TAG, "oCF " + connectionResult.toString());
    }
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(mActivity, ActivityUtils.RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), mActivity, 0).show();
    }
}
 
源代码12 项目: easygoogle   文件: GacFragment.java
private void showErrorDialog(ConnectionResult connectionResult) {
    int errorCode = connectionResult.getErrorCode();

    if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
        // Show the default Google Play services error dialog which may still start an intent
        // on our behalf if the user can resolve the issue.
        GooglePlayServicesUtil.getErrorDialog(errorCode, getActivity(), mResolutionCode,
                new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        mShouldResolve = false;
                    }
                }).show();
    } else {
        // No default Google Play Services error, display a message to the user.
        String errorString = getString(R.string.play_services_error_fmt, errorCode);
        Toast.makeText(getActivity(), errorString, Toast.LENGTH_SHORT).show();
        mShouldResolve = false;
    }
}
 
源代码13 项目: GCMPushPlugin   文件: GCMPushPlugin.java
/**
 * Check the device to make sure it has the Google Play Services APK. If
 * it doesn't, display a dialog that allows users to download the APK from
 * the Google Play Store or enable it in the device's system settings.
 */
private boolean checkPlayServices() {
    final int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(cordova.getActivity());
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    GooglePlayServicesUtil.getErrorDialog(resultCode, cordova.getActivity(), 9000).show();
                }
            });
        } else {
            Log.i(TAG, "This device is not supported.");
            cordova.getActivity().finish();
        }
        return false;
    }
    return true;
}
 
源代码14 项目: FORMWatchFace   文件: ConfigHelper.java
public boolean connect() {
    if (mGoogleApiClient != null) {
        return true;
    }

    if (ConnectionResult.SUCCESS != GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext)
            || Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return false;
    }

    mGoogleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();
    ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(5, TimeUnit.SECONDS);
    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode());
        mGoogleApiClient = null;
        return false;
    }

    return true;
}
 
源代码15 项目: edx-app-android   文件: GoogleOauth2.java
private void pickUserAccount() {
    try {
        String[] accountTypes = new String[]{"com.google"};
        Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                accountTypes, true, null, null, null, null);
        if ( activity == null )
            return;
        // check if play-services are installed
        int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
        if (ConnectionResult.SUCCESS == result) {
            activity.startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
            logger.debug("Launching google account picker ...");
        } else {
            // display user friendly error message
            logger.debug("Play services are missing ...");
            GooglePlayServicesUtil.getErrorDialog(result, activity, 100).show();
        }
    } catch (ActivityNotFoundException ex) {
        logger.debug("Google-play-services are missing? cannot login by google");
    }
}
 
源代码16 项目: chess   文件: Main.java
@Override
public void onConnectionFailed(final ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        // This problem can be fixed. So let's try to fix it.
        try {
            // launch appropriate UI flow (which might, for example, be the
            // sign-in flow)
            connectionResult.startResolutionForResult(this, RC_RESOLVE);
        } catch (IntentSender.SendIntentException e) {
            // Try connecting again
            mGoogleApiClient.connect();
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}
 
源代码17 项目: android-map_list   文件: MapListActivity.java
@Override
protected void onResume() {
    super.onResume();

    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (resultCode == ConnectionResult.SUCCESS) {
        mRecyclerView.setAdapter(mListAdapter);
    } else {
        GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1).show();
    }

    if (mListAdapter != null) {
        for (MapView m : mListAdapter.getMapViews()) {
            m.onResume();
        }
    }
}
 
源代码18 项目: vocefiscal-android   文件: MapsActivity.java
/**
 * Check the device to make sure it has the Google Play Services APK. If
 * it doesn't, display a dialog that allows users to download the APK from
 * the Google Play Store or enable it in the device's system settings.
 */
private boolean checkPlayServices() 
{
	int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
	if (resultCode != ConnectionResult.SUCCESS) 
	{
		if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) 
		{
			GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
		} else 
		{
			finish();
		}
		return false;
	}
	return true;
}
 
源代码19 项目: HRCarMarkerAnimation   文件: MainActivity.java
private boolean isGooglePlayServicesAvailable() {
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (ConnectionResult.SUCCESS == status) {
        return true;
    } else {
        GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
        return false;
    }
}
 
源代码20 项目: TelePlus-Android   文件: ApplicationLoader.java
private boolean checkPlayServices()
{
    try
    {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        return resultCode == ConnectionResult.SUCCESS;
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
    return true;
}
 
源代码21 项目: FlappyCow   文件: BaseGameUtils.java
/**
 * 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;
    }
}
 
源代码22 项目: TelePlus-Android   文件: ApplicationLoader.java
private boolean checkPlayServices()
{
    try
    {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        return resultCode == ConnectionResult.SUCCESS;
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
    return true;
}
 
源代码23 项目: Asteroid   文件: BaseGameUtils.java
/**
 * Show a {@link android.app.Dialog} with the correct message for a connection error.
 *
 * @param activity         the Activity in which the Dialog should be displayed.
 * @param requestCode      the request code from onActivityResult.
 * @param actResp          the response code from onActivityResult.
 * @param errorDescription the resource id of a String for a generic error message.
 */
public static void showActivityResultError(AppCompatActivity activity, int requestCode, int actResp, int errorDescription) {
    if (activity == null) {
        Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
        return;
    }
    Dialog errorDialog;

    switch (actResp) {
        case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.app_misconfigured));
            break;
        case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.sign_in_failed));
            break;
        case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.license_failed));
            break;
        default:
            // No meaningful Activity response code, so generate default Google
            // Play services dialog
            final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
            errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                    activity, requestCode, null);
            if (errorDialog == null) {
                // get fallback dialog
                Log.e("BaseGamesUtils",
                        "No standard error dialog available. Making fallback dialog.");
                errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription));
            }
    }

    errorDialog.show();
}
 
/**
 * Checks if Google Play Services are installed and if not it initializes opening the dialog to
 * allow user to install Google Play Services.
 */
private boolean checkGooglePlayServicesAvailable() {
  final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
    showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
    return false;
  }
  return true;
}
 
源代码25 项目: financisto   文件: MenuListActivity.java
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDriveConnectionFailed(DriveConnectionFailed event) {
    dismissProgressDialog();
    ConnectionResult connectionResult = event.connectionResult;
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
            onDriveBackupError(new DriveBackupError(e.getMessage()));
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}
 
源代码26 项目: financisto   文件: MenuListActivity.java
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDriveBackupFailed(DriveBackupFailure event) {
    dismissProgressDialog();
    Status status = event.status;
    if (status.hasResolution()) {
        try {
            status.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
            onDriveBackupError(new DriveBackupError(e.getMessage()));
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(status.getStatusCode(), this, 0).show();
    }
}
 
源代码27 项目: ToDay   文件: TheHubActivity.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    /* Callback can be invoked if user has not previously authorized the app. */
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, AppConstants.EXPORT_RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        Toast.makeText(this, R.string.feedback_failed_msg, Toast.LENGTH_LONG).show();
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }

}
 
/**
 * Check that Google Play services APK is installed and up to date.
 */
private boolean checkGooglePlayServicesAvailable() {
  final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
    showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
    return false;
  }
  return true;
}
 
源代码29 项目: Trivia-Knowledge   文件: BaseGameUtils.java
/**
 * 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,
                                               int 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, activity.getString(fallbackErrorMessage));
        }
        return false;
    }
}
 
源代码30 项目: Trivia-Knowledge   文件: BaseGameUtils.java
/**
 * Show a {@link android.app.Dialog} with the correct message for a connection error.
 *  @param activity the Activity in which the Dialog should be displayed.
 * @param requestCode the request code from onActivityResult.
 * @param actResp the response code from onActivityResult.
 * @param errorDescription the resource id of a String for a generic error message.
 */
public static void showActivityResultError(Activity activity, int requestCode, int actResp, int errorDescription) {
    if (activity == null) {
        Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
        return;
    }
    Dialog errorDialog;

    switch (actResp) {
        case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.app_misconfigured));
            break;
        case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.sign_in_failed));
            break;
        case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
            errorDialog = makeSimpleDialog(activity,
                    activity.getString(R.string.license_failed));
            break;
        default:
            // No meaningful Activity response code, so generate default Google
            // Play services dialog
            final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
            errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                    activity, requestCode, null);
            if (errorDialog == null) {
                // get fallback dialog
                Log.e("BaseGamesUtils",
                        "No standard error dialog available. Making fallback dialog.");
                errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription));
            }
    }

    errorDialog.show();
}