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

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

源代码1 项目: social-app-android   文件: GoogleApiHelper.java
public static GoogleApiClient createGoogleApiClient(FragmentActivity fragmentActivity) {
    GoogleApiClient.OnConnectionFailedListener failedListener;

    if (fragmentActivity instanceof GoogleApiClient.OnConnectionFailedListener) {
        failedListener = (GoogleApiClient.OnConnectionFailedListener) fragmentActivity;
    } else {
        throw new IllegalArgumentException(fragmentActivity.getClass().getSimpleName() + " should implement OnConnectionFailedListener");
    }

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(fragmentActivity.getResources().getString(R.string.google_web_client_id))
            .requestEmail()
            .build();

    return new GoogleApiClient.Builder(fragmentActivity)
            .enableAutoManage(fragmentActivity, failedListener)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
}
 
源代码2 项目: android-Geofencing   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Rather than displayng this activity, simply display a toast indicating that the geofence
    // service is being created. This should happen in less than a second.
    if (!isGooglePlayServicesAvailable()) {
        Log.e(TAG, "Google Play services unavailable.");
        finish();
        return;
    }

    mApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    mApiClient.connect();

    // Instantiate a new geofence storage area.
    mGeofenceStorage = new SimpleGeofenceStore(this);
    // Instantiate the current List of geofences.
    mGeofenceList = new ArrayList<Geofence>();
    createGeofences();
}
 
源代码3 项目: io2015-codelabs   文件: UtilityService.java
/**
 * Add geofences using Play Services
 */
private void addGeofencesInternal() {
    Log.v(TAG, ACTION_ADD_GEOFENCES);
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .build();

    // It's OK to use blockingConnect() here as we are running in an
    // IntentService that executes work on a separate (background) thread.
    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (connectionResult.isSuccess() && googleApiClient.isConnected()) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                this, 0, new Intent(this, UtilityReceiver.class), 0);
        GeofencingApi.addGeofences(googleApiClient,
                TouristAttractions.getGeofenceList(), pendingIntent);
        googleApiClient.disconnect();
    } else {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
    }
}
 
源代码4 项目: android-Quiz   文件: QuizReportActionService.java
@Override
public void onHandleIntent(Intent intent) {
    if (intent.getAction().equals(ACTION_RESET_QUIZ)) {
        final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .build();
        ConnectionResult result = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS,
                TimeUnit.MILLISECONDS);
        if (!result.isSuccess()) {
            Log.e(TAG, "QuizReportActionService failed to connect to GoogleApiClient.");
            return;
        }

        CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi
                .getCapability(googleApiClient, RESET_QUIZ_CAPABILITY_NAME,
                        CapabilityApi.FILTER_REACHABLE)
                .await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS);
        if (capabilityResult.getStatus().isSuccess()) {
            sendResetMessage(googleApiClient, capabilityResult.getCapability());
        } else {
            Log.e(TAG, "Failed to get capabilities, status: "
                    + capabilityResult.getStatus().getStatusMessage());
        }
    }
}
 
源代码5 项目: financisto   文件: GoogleDriveClient.java
private ConnectionResult connect() throws ImportExportException {
    if (googleApiClient == null) {
        String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
        if (googleDriveAccount == null) {
            throw new ImportExportException(R.string.google_drive_account_required);
        }
        googleApiClient = new GoogleApiClient.Builder(context)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .setAccountName(googleDriveAccount)
                //.addConnectionCallbacks(this)
                //.addOnConnectionFailedListener(this)
                .build();
    }
    return googleApiClient.blockingConnect(1, TimeUnit.MINUTES);
}
 
源代码6 项目: EasyFirebase   文件: EasyFirebaseAuth.java
public EasyFirebaseAuth(GoogleApiClient googleApiClient) {
    mAuth = FirebaseAuth.getInstance();
    this.googleApiClient = googleApiClient;

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            final FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                if (firebaseUserSubscriber != null) {
                    firebaseUserSubscriber.onNext(new Pair<GoogleSignInAccount, FirebaseUser>(googleSignInAccount, user));
                    firebaseUserSubscriber.onCompleted();
                }
                if (loggedSubcriber != null) {
                    loggedSubcriber.onNext(user);
                }
                // User is signed in
                Log.d("TAG", "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d("TAG", "onAuthStateChanged:signed_out");
            }
        }
    };
}
 
源代码7 项目: attendee-checkin   文件: BaseActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Google+ Sign in
    mApiClient = new GoogleApiClient.Builder(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mConnectionProgressDialog = new ProgressDialog(this);
    mConnectionProgressDialog.setMessage(getString(R.string.signing_in));
    GutenbergApplication app = GutenbergApplication.from(this);
    if (!app.isUserLoggedIn()) {
        selectAccount(false);
    } else {
        app.requestSync(false);
    }
    adjustTaskDescription();
}
 
源代码8 项目: AndroidProgramming3e   文件: LocatrFragment.java
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    mClient = new GoogleApiClient.Builder(getActivity()).addApi(LocationServices.API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle bundle) {
                    getActivity().invalidateOptionsMenu();
                }

                @Override
                public void onConnectionSuspended(int i) {

                }
            })
            .build();
}
 
源代码9 项目: wearabird   文件: DeviceClient.java
public void sendSensorData(final int sensorType, final int accuracy, final long timestamp, final float[] values) {
	ConnectionManager.getInstance(context).sendMessage(new ConnectionManager.ConnectionManagerRunnable(context) {
		@Override
		public void send(GoogleApiClient googleApiClient) {
			PutDataMapRequest dataMap = PutDataMapRequest.create("/sensors/" + sensorType);

			dataMap.getDataMap().putInt(DataMapKeys.ACCURACY, accuracy);
			dataMap.getDataMap().putLong(DataMapKeys.TIMESTAMP, timestamp);
			dataMap.getDataMap().putFloatArray(DataMapKeys.VALUES, values);

			PutDataRequest putDataRequest = dataMap.asPutDataRequest();

			Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
		}
	});
}
 
private synchronized void buildGoogleApiClient() {
    googleApiClient = new GoogleApiClient.Builder(getActivity())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
}
 
源代码11 项目: braintree_android   文件: BraintreeFragmentTest.java
@Test(timeout = 6000)
public void getGoogleApiClient_returnsGoogleApiClient() throws InterruptedException {
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, mClientToken);

    fragment.getGoogleApiClient(new BraintreeResponseListener<GoogleApiClient>() {
        @Override
        public void onResponse(GoogleApiClient googleApiClient) {
            assertNotNull(googleApiClient);
            mCountDownLatch.countDown();
        }
    });

    mCountDownLatch.await();
}
 
源代码12 项目: LibreAlarm   文件: WearService.java
@Override
public void onCreate() {
    super.onCreate();
    setupTextToSpeech();
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mGoogleApiClient.connect();
}
 
源代码13 项目: friendspell   文件: GoogleApiClientBridge.java
public void unsubscribe(String token, MessageListener listener, ResultCallback<Status> callback) {
  GoogleApiClient googleApiClient = clients.get(token);
  if (googleApiClient.isConnected()) {
    Nearby.Messages.unsubscribe(googleApiClient, listener)
        .setResultCallback(callback);
  }
}
 
源代码14 项目: ExamplesAndroid   文件: MainActivity.java
protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
    mGoogleApiClient.connect();


}
 
源代码15 项目: wear-os-samples   文件: Utils.java
/**
 * Get a list of all wearable nodes that are connected synchronously.
 * Only call this method from a background thread (it should never be
 * called from the main/UI thread as it blocks).
 */
public static Collection<String> getNodes(GoogleApiClient client) {
    Collection<String> results= new HashSet<String>();
    NodeApi.GetConnectedNodesResult nodes =
            Wearable.NodeApi.getConnectedNodes(client).await();
    for (Node node : nodes.getNodes()) {
        results.add(node.getId());
    }
    return results;
}
 
源代码16 项目: io.appium.settings   文件: LocationService.java
private FusedLocationProvider createFusedLocationProvider() {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .build();
    FusedLocationProviderClient locationProviderClient = LocationServices.getFusedLocationProviderClient(this);
    return new FusedLocationProvider(googleApiClient, locationProviderClient, this);
}
 
源代码17 项目: Trivia-Knowledge   文件: SnapshotCoordinator.java
@Override
public PendingResult<OpenSnapshotResult> resolveConflict(GoogleApiClient googleApiClient,
                                                         String conflictId,
                                                         final Snapshot snapshot) {
    if (!isAlreadyOpen(snapshot.getMetadata().getUniqueName()) &&
            !isAlreadyClosing(snapshot.getMetadata().getUniqueName())) {
        setIsOpening(snapshot.getMetadata().getUniqueName());
        try {
            return new CoordinatedPendingResult<>(
                    Games.Snapshots.resolveConflict(googleApiClient, conflictId, snapshot),
                    new ResultListener() {
                        @Override
                        public void onResult(Result result) {
                            if (!result.getStatus().isSuccess()) {
                                setClosed(snapshot.getMetadata().getUniqueName());
                            }
                        }
                    });
        } catch (RuntimeException e) {
            setClosed(snapshot.getMetadata().getUniqueName());
            throw e;
        }
    } else {
        throw new IllegalStateException(snapshot.getMetadata().getUniqueName() +
                " is already open or is busy");
    }
}
 
源代码18 项目: flopsydroid   文件: MyActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    mBtnOnWearable = (ImageView) findViewById(R.id.startWearable);
    mBtnOnWearable.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getNodes(new OnGotNodesListener() {
                @Override
                public void onGotNodes(ArrayList<String> nodes) {
                    if(nodes.size() > 0) {
                        Wearable.MessageApi.sendMessage(
                                getGoogleApiClient(), nodes.get(0), "/flopsydroid/wear", null).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                            @Override
                            public void onResult(MessageApi.SendMessageResult result) {
                                if (!result.getStatus().isSuccess()) {
                                }
                            }
                        });
                    }
                }
            });
        }
    });

    mGoogleAppiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Wearable.API)
            .build();
}
 
源代码19 项目: io2015-codelabs   文件: UtilityService.java
/**
 * Sends the actual message to ask other devices that are capable of showing "details" to start
 * the appropriate activity
 *
 * @param path the path to pass to the wearable message API
 * @param extraInfo extra info that varies based on the path being sent
 */
private void startDeviceActivityInternal(String path, String extraInfo) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (connectionResult.isSuccess() && googleApiClient.isConnected()) {
        CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability(
                googleApiClient,
                getApplicationContext().getString(R.string.show_detail_capability_name),
                CapabilityApi.FILTER_REACHABLE)
                .await(GET_CAPABILITY_TIMEOUT_S, TimeUnit.SECONDS);
        if (result.getStatus().isSuccess()) {
            Set<Node> nodes = result.getCapability().getNodes();
            for (Node node : nodes) {
                Wearable.MessageApi.sendMessage(
                        googleApiClient, node.getId(), path, extraInfo.getBytes());
            }
        } else {
            Log.e(TAG, "startDeviceActivityInternal() Failed to get capabilities, status: "
                    + result.getStatus().getStatusMessage());
        }

        googleApiClient.disconnect();
    }
}
 
源代码20 项目: Onesearch   文件: GameHelper.java
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
源代码21 项目: ETSMobile-Android2   文件: MainActivity.java
private String getRemoteNodeId(GoogleApiClient googleApiClient) {
    NodeApi.GetConnectedNodesResult nodesResult =
            Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    List<Node> nodes = nodesResult.getNodes();
    if (nodes.size() > 0) {
        return nodes.get(0).getId();
    }
    return null;
}
 
private void initGoogleApiClient() {
  mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
          .addApi(Wearable.API)
          .addConnectionCallbacks(new WearConnectionCallbacks())
          .addOnConnectionFailedListener(new WearConnectionFailedListener())
          .build();
  mGoogleApiClient.connect();
}
 
private synchronized void buildGoogleApiClient(@NonNull Context context) {
    mGoogleApiClient = new GoogleApiClient.Builder(context.getApplicationContext())         // Use getApplicationContext to prevent memory leak: https://stackoverflow.com/questions/35308231/memory-leak-with-googleapiclient-detected-by-android-studio
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
}
 
源代码24 项目: journaldev   文件: SecondActivity.java
public void setUpGoogleApiClient() {

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addApi(Auth.CREDENTIALS_API)
                .enableAutoManage(this, this)
                .build();
    }
 
源代码25 项目: andela-med-manager   文件: AuthActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_auth);
    ButterKnife.bind(this);

    addUserViewModel = ViewModelProviders.of(this).get(AddUserViewModel.class);

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    // Build a GoogleApiClient with access to the Google Sign-In Api and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivitgit y */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    loginButton.setOnClickListener(v -> {
        //Check Internet Connection
        //  if (NetworkUtil.isConnected(this))
        googleSignIn();

    });
}
 
@Override
public ApiConnection build(Context context, Looper looper,
        Api.ApiOptions.NoOptions options,
        AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks,
        GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
    return new LocationClientImpl(context, callbacks, connectionFailedListener);
}
 
源代码27 项目: firebase-android-sdk   文件: DynamicLinksClient.java
public DynamicLinksClient(
    Context context,
    Looper looper,
    ClientSettings clientSettings,
    GoogleApiClient.ConnectionCallbacks connectedListener,
    GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
  super(
      context,
      looper,
      // ServiceId.DYNAMIC_LINKS_API_VALUE,
      131,
      clientSettings,
      connectedListener,
      connectionFailedListener);
}
 
源代码28 项目: social-app-android   文件: LogoutHelper.java
private static void logoutByProvider(String providerId, GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    switch (providerId) {
        case GoogleAuthProvider.PROVIDER_ID:
            logoutGoogle(mGoogleApiClient, fragmentActivity);
            break;

        case FacebookAuthProvider.PROVIDER_ID:
            logoutFacebook(fragmentActivity.getApplicationContext());
            break;
    }
}
 
源代码29 项目: AndroidWearable-Samples   文件: SetTimerActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int paramLength = getIntent().getIntExtra(AlarmClock.EXTRA_LENGTH, 0);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "SetTimerActivity:onCreate=" + paramLength);
    }
    if (paramLength > 0 && paramLength <= 86400) {
        long durationMillis = paramLength * 1000;
        setupTimer(durationMillis);
        finish();
        return;
    }

    Resources res = getResources();
    for (int i = 0; i < NUMBER_OF_TIMES; i++) {
        mTimeOptions[i] = new ListViewItem(
                res.getQuantityString(R.plurals.timer_minutes, i + 1, i + 1),
                (i + 1) * 60 * 1000);
    }

    setContentView(R.layout.timer_set_timer);

    // Initialize a simple list of countdown time options.
    mListView = (ListView) findViewById(R.id.times_list_view);
    ArrayAdapter<ListViewItem> arrayAdapter = new ArrayAdapter<ListViewItem>(this,
            android.R.layout.simple_list_item_1, mTimeOptions);
    mListView.setAdapter(arrayAdapter);
    mListView.setOnItemClickListener(this);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
 
源代码30 项目: friendlyping   文件: RegistrationIntentService.java
/**
 * Sends the registration to the server.
 *
 * @param token The token to send.
 * @throws IOException Thrown when a connection issue occurs.
 */
private void sendRegistrationToServer(String token) throws IOException {
    final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .build();
    googleApiClient.blockingConnect();

    Bundle registration = createRegistrationBundle(googleApiClient);
    registration.putString(PingerKeys.REGISTRATION_TOKEN, token);

    // Register the user at the server.
    GoogleCloudMessaging.getInstance(this).send(FriendlyPingUtil.getServerUrl(this),
            String.valueOf(System.currentTimeMillis()), registration);
}