本文整理匯總了Java中com.google.android.gms.common.api.GoogleApiClient類的典型用法代碼示例。如果您正苦於以下問題:Java GoogleApiClient類的具體用法?Java GoogleApiClient怎麽用?Java GoogleApiClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GoogleApiClient類屬於com.google.android.gms.common.api包,在下文中一共展示了GoogleApiClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initGoogleApiClient
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
private void initGoogleApiClient() {
final GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.requestScopes(new Scope(SCOPE_PICASA))
.build();
googleApiClient = new GoogleApiClient.Builder(activity)
.enableAutoManage(activity,
connectionResult -> emitter.onError(new SignInException("Connecting", connectionResult.getErrorMessage(), connectionResult.getErrorCode())))
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
actWhenConnected();
}
@Override
public void onConnectionSuspended(int i) {
}
})
.build();
}
示例2: createApiClientBuilder
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
/**
* 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_SNAPSHOT)) {
builder.addScope(Drive.SCOPE_APPFOLDER);
builder.addApi(Drive.API);
}
mGoogleApiClientBuilder = builder;
return builder;
}
示例3: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnIncreaseCounter = (Button) findViewById(R.id.btnWearIncreaseCounter);
btnIncreaseCounter.getBackground().setColorFilter(0xFF1194F7, PorterDuff.Mode.MULTIPLY);
tvCounter = (TextView) findViewById(R.id.tvCounter);
tvCounter.setText(Integer.toString(count));
client = new GoogleApiClient.Builder(this).addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
btnIncreaseCounter.setOnClickListener(clickListener);
}
示例4: setupGeoLocation
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
private void setupGeoLocation() {
Log.d(TAG, "setupGeoLocation()");
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10 * 60 * 1000); // 10 minutes, in milliseconds
mLocationRequest.setFastestInterval(60 * 1000); // 60 second, in milliseconds
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // We wanto to center the Player on his actual position
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true); // "This app wants to change your device settings for GPS location"
mLocationSettingsRequest = builder.build();
}
示例5: delete
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
public PendingResult<DeleteSnapshotResult> delete(GoogleApiClient googleApiClient,
final SnapshotMetadata snapshotMetadata) {
if (!isAlreadyOpen(snapshotMetadata.getUniqueName()) &&
!isAlreadyClosing(snapshotMetadata.getUniqueName())) {
setIsClosing(snapshotMetadata.getUniqueName());
try {
return new CoordinatedPendingResult<>(
Games.Snapshots.delete(googleApiClient, snapshotMetadata),
new ResultListener() {
@Override
public void onResult(Result result) {
// deleted files are closed.
setClosed(snapshotMetadata.getUniqueName());
}
});
} catch (RuntimeException e) {
setClosed(snapshotMetadata.getUniqueName());
throw e;
}
} else {
throw new IllegalStateException(snapshotMetadata.getUniqueName() +
" is either open or is busy");
}
}
示例6: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBundle = savedInstanceState;
if (getArguments() != null) {
proyectos = getArguments().getParcelableArrayList(ARG_PROYECTOS);
}
//Para localizar al usuario inicializo la variable de la API de Google Maps
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
}
示例7: ClearAccount
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
public void ClearAccount(){
Log.i(TAG, "Clearing Google API Account");
GoogleApiClient mAPI = getGoogleApiClient();
if (mAPI != null) {
if(mAPI.isConnected()){
mAPI.clearDefaultAccountAndReconnect();
Log.i(TAG, "Clear account and reconnect called");
} else {
Log.w(TAG, "Google API client not connected when attempting disconnect");
Toast.makeText(this, "Google API not connected. Make sure WiFi is On.", Toast.LENGTH_LONG).show();
}
} else {
Log.w(TAG, "Google API was null when attempting to disconnect account");
}
stopSelf(mStartID);
}
示例8: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the Google Api Client with access to Games
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
// set up a click listener for everything we care about
for (int id : CLICKABLES) {
findViewById(id).setOnClickListener(this);
}
}
示例9: initialize
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
/**
* Initializes the GoogleApiClient. Give your main AndroidLauncher as context.
* <p>
* Don't forget to add onActivityResult method there with call to onGpgsActivityResult.
*
* @param context your AndroidLauncher class
* @param enableDriveAPI true if you activate save gamestate feature
* @return this for method chunking
*/
public GpgsClient initialize(Activity context, boolean enableDriveAPI) {
if (mGoogleApiClient != null)
throw new IllegalStateException("Already initialized.");
myContext = context;
// retry some times when connect fails (needed when game state sync is enabled)
firstConnectAttempt = MAX_CONNECTFAIL_RETRIES;
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(myContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES);
driveApiEnabled = enableDriveAPI;
if (driveApiEnabled)
builder.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER);
// add other APIs and scopes here as needed
mGoogleApiClient = builder.build();
return this;
}
示例10: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
initUI();
if (loginViewModel.isLogin()) {
showProgress(true);
Single.timer(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
finish();
startActivity(new Intent(LoginActivity.this, AppArchNavigationDrawer.class));
});
} else {
loginView();
}
}
示例11: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
// Create an instance of GoogleAPIClient.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
}
示例12: setDevice
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
private void setDevice(CastDevice device) {
mSelectedCastDevice = device;
mDeviceName = mSelectedCastDevice.getFriendlyName();
if (mApiClient == null) {
LOGD(TAG, "acquiring a connection to Google Play services for " + mSelectedCastDevice);
Cast.CastOptions.Builder apiOptionsBuilder = getCastOptionBuilder(mSelectedCastDevice);
mApiClient = new GoogleApiClient.Builder(mContext)
.addApi(Cast.API, apiOptionsBuilder.build())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mApiClient.connect();
} else if (!mApiClient.isConnected() && !mApiClient.isConnecting()) {
mApiClient.connect();
}
}
示例13: initView
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
private void initView()
{
fragmentAlert =new Fragment_display_alertes();
fragmentMeasures=new Fragment_display_measures();
fragmentSettings =new Fragment_display_settings();
//add the fragment to the fragment manager
getSupportFragmentManager().beginTransaction().add(R.id.main_container,fragmentAlert,"alertFrag").commit();
getSupportFragmentManager().beginTransaction().add(R.id.main_container,fragmentMeasures,"measureFrag").commit();
getSupportFragmentManager().beginTransaction().add(R.id.main_container,fragmentSettings,"settingsFrag").commit();
//INIT the googe client
googleClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
示例14: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.teacher_gradingfactor_activity_midterm);
try {
subject = subjectService.getSubjectById(getIntent().getExtras().getLong("subjectId"));
formula = formulaService.getFormulaById(getIntent().getExtras().getLong("formulaId"));
teacher = new TeacherHelper(this).loadUser().get();
isExist = getIntent().getExtras().getBoolean("isExist");
init();
ArrayAdapter<String> spinnerAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, values);
spinnerm.setAdapter(spinnerAdapter);
} catch (Exception e) {
e.printStackTrace();
}
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
示例15: onCreate
import com.google.android.gms.common.api.GoogleApiClient; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Urbino.instance().getAppGraph().inject(this);
signinPresenter.attachView(this);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
googleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this::onFailApiClientFail)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setOnClickListener(this::onSignInClick);
}