本文整理汇总了Java中com.google.android.gms.common.api.Scope类的典型用法代码示例。如果您正苦于以下问题:Java Scope类的具体用法?Java Scope怎么用?Java Scope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Scope类属于com.google.android.gms.common.api包,在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LoginGoogle
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
public LoginGoogle(final Context context, SignInButton button, final Activity act, PreferencesShared pref) {
this.context = context;
preferencesShared = pref;
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken("473547758853-nm840bumsu5km04gbgtdee1fhtod1ji6.apps.googleusercontent.com").build();
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)).requestScopes(new Scope(Scopes.PLUS_ME)).requestEmail().requestIdToken("473547758853-nm840bumsu5km04gbgtdee1fhtod1ji6.apps.googleusercontent.com").build();
mGoogleApiClient = new GoogleApiClient.Builder(context.getApplicationContext())
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
button.setSize(SignInButton.SIZE_STANDARD);
button.setScopes(gso.getScopeArray());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
act.startActivityForResult(signInIntent, 101);
}
});
}
示例2: initGoogleApiClient
import com.google.android.gms.common.api.Scope; //导入依赖的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();
}
示例3: init
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
public void init (final int instanceID) {
script_id = instanceID;
GUtils.setScriptInstance(script_id);
if (GUtils.checkGooglePlayService(activity)) {
Log.d(TAG, "Play Service Available.");
}
GoogleSignInOptions gso =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestScopes(new Scope(Scopes.GAMES))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(activity, gso);
Log.d(TAG, "Google::Initialized");
onStart();
}
示例4: loginGoogleAPI
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
private void loginGoogleAPI() {
if (!(context instanceof FragmentActivity)) {
return;
}
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.requestId()
.requestScopes(new Scope(Scopes.PLUS_LOGIN), new Scope(Scopes.DRIVE_FILE))
.requestServerAuthCode(CLIENT_ID)
.build();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addApi(com.google.android.gms.auth.api.Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
if (!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
} else {
sendAuthRequest();
}
}
示例5: exchangeServerAuthCodeForJWT
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
private void exchangeServerAuthCodeForJWT(String firebaseUserId, String authCode, Set<Scope> grantedScopes, final SimpleCallback<String> jwtCallback) {
Ion.with(context)
.load(context.getString(R.string.APP_URL) + "/exchangeServerAuthCodeForJWT")
.setBodyParameter("serverCode", authCode)
.setBodyParameter("firebaseUserId", firebaseUserId)
.setBodyParameter("grantedScopes", android.text.TextUtils.join(",", grantedScopes))
.asJsonObject()
.setCallback(new com.koushikdutta.async.future.FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (e != null) {
jwtCallback.onError(e);
return;
}
String jwt = result.get("serviceAccessToken").getAsString();
AuthHelper.userJwt = jwt;
jwtCallback.onComplete(jwt);
}
});
}
示例6: requestPermissions
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Override
public int requestPermissions(Activity activity) {
AuthHelper authHelper = new AuthHelper(context);
Set<Scope> scopes = new HashSet<>();
scopes.addAll(AuthHelper.grantedScopes);
scopes.add(new Scope(RequiredScope));
GoogleApiClient mGoogleApiClient = new GoogleApiClient
.Builder(context)
.addApi(Auth.GOOGLE_SIGN_IN_API, authHelper.getGoogleGSO(scopes))
.build();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
activity.startActivityForResult(signInIntent, GoogleCalendarSettings.PERMISSIONS_REQUEST_READ_GOOGLE_CALENDAR);
return GoogleCalendarSettings.PERMISSIONS_REQUEST_READ_GOOGLE_CALENDAR;
}
示例7: createConnection
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
public void createConnection(AppCompatActivity mActivity)
{
this.activity = mActivity;
userData = new UserLoginDetails();
if (Utility.checkPlayServices(mActivity)) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.PROFILE))
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestProfile()
.requestEmail()
.build();
if (mGoogleApiClient == null) {
// [START create_google_api_client]
// Build GoogleApiClient with access to basic profile
mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
.enableAutoManage(mActivity,this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
//.addApi(Plus.API)
.build();
}
}
}
示例8: testLoginGoogleSuccess
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Test public void testLoginGoogleSuccess() throws Exception {
InOrder inOrder = inOrder(mMockGoogleApiClient);
mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
.subscribe(mGoogleSubscriber);
// wait for connection
Thread.sleep(20);
mRxLogin.mGoogleCallback.onSuccess(mGoogleSignInResult);
mGoogleSubscriber.awaitTerminalEvent();
verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
inOrder.verify(mMockGoogleApiClient).disconnect();
mGoogleSubscriber.assertNoErrors();
mGoogleSubscriber.assertValueCount(1);
mGoogleSubscriber.assertTerminated();
assertThat(mRxLogin.mGoogleApiClient).isNull();
assertThat(mRxLogin.mGoogleCallback).isNull();
}
示例9: testLoginGoogleCancel
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Test public void testLoginGoogleCancel() throws Exception {
InOrder inOrder = inOrder(mMockGoogleApiClient);
mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
.subscribe(mGoogleSubscriber);
// wait for connection
Thread.sleep(20);
mRxLogin.mGoogleCallback.onCancel();
mGoogleSubscriber.awaitTerminalEvent();
verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
inOrder.verify(mMockGoogleApiClient).disconnect();
mGoogleSubscriber.assertError(LoginException.class);
mGoogleSubscriber.assertTerminated();
assertThat(mRxLogin.mGoogleApiClient).isNull();
assertThat(mRxLogin.mGoogleCallback).isNull();
}
示例10: testLoginGoogleError
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Test public void testLoginGoogleError() throws Exception {
InOrder inOrder = inOrder(mMockGoogleApiClient);
mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
.subscribe(mGoogleSubscriber);
// wait for connection
Thread.sleep(20);
mRxLogin.mGoogleCallback.onError(mGoogleSignInResult);
mGoogleSubscriber.awaitTerminalEvent();
verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
inOrder.verify(mMockGoogleApiClient).disconnect();
mGoogleSubscriber.assertError(LoginException.class);
mGoogleSubscriber.assertTerminated();
assertThat(mRxLogin.mGoogleApiClient).isNull();
assertThat(mRxLogin.mGoogleCallback).isNull();
}
示例11: testLoginGoogleConnectionError
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Test public void testLoginGoogleConnectionError() throws Exception {
when(mMockGoogleApiClient.blockingConnect(eq(10L), eq(TimeUnit.SECONDS)))
.thenReturn(new ConnectionResult(ConnectionResult.API_UNAVAILABLE));
InOrder inOrder = inOrder(mMockGoogleApiClient);
mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
.subscribe(mGoogleSubscriber);
mGoogleSubscriber.awaitTerminalEvent();
verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
inOrder.verify(mMockGoogleApiClient).disconnect();
mGoogleSubscriber.assertError(LoginException.class);
mGoogleSubscriber.assertTerminated();
assertThat(mRxLogin.mGoogleApiClient).isNull();
assertThat(mRxLogin.mGoogleCallback).isNull();
}
示例12: loadDriveApiClients
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
private void loadDriveApiClients() {
Set<Scope> requiredScopes = new HashSet<>(2);
requiredScopes.add(Drive.SCOPE_FILE);
requiredScopes.add(Drive.SCOPE_APPFOLDER);
GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(getContext());
if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) {
initializeDriveClient(signInAccount);
} else {
GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_FILE)
.requestScopes(Drive.SCOPE_APPFOLDER)
.build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(getActivity(), signInOptions);
startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_RESOLVE_ERROR);
}
}
示例13: onCreate
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.historydata_layout);
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mAggregateCheckBox = (CheckBox)findViewById(R.id.aggregatecheckbox);
mStartDateText = (TextView)findViewById(R.id.startdate);
mEndDateText = (TextView)findViewById(R.id.enddate);
mResultsText = (TextView)findViewById(R.id.results);
setUpSpinnerDropDown();
setUpListView();
}
示例14: onCreate
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscriptiondata_layout);
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.RECORDING_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
setUpSpinnerDropDown();
setUpListView();
}
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:19,代码来源:SubscriptionActivity.java
示例15: onCreate
import com.google.android.gms.common.api.Scope; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sensordata_layout);
mLiveDataText = (TextView)findViewById(R.id.livedata);
setUpSpinnerDropDown();
setUpListView();
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}