當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleAccountCredential.usingAudience方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.usingAudience方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleAccountCredential.usingAudience方法的具體用法?Java GoogleAccountCredential.usingAudience怎麽用?Java GoogleAccountCredential.usingAudience使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential的用法示例。


在下文中一共展示了GoogleAccountCredential.usingAudience方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initGAEService

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
private void initGAEService() {
    if (service != null) {
        return;
    }
    if (mGoogleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(mContext,
            "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(mGoogleSignInAccount.getEmail());
    Log.d(TAG, "credential account name" + credential.getSelectedAccountName());
    U2fRequestHandler.Builder builder = new U2fRequestHandler.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), credential)
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(
                        AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                        throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });
    service = builder.build();
}
 
開發者ID:googlesamples,項目名稱:android-fido,代碼行數:25,代碼來源:GAEService.java

示例2: get

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public static Messaging get(Context context){
    if (messagingService == null) {
        SharedPreferences settings = context.getSharedPreferences(
                "Watchpresenter", Context.MODE_PRIVATE);
        final String accountName = settings.getString(Constants.PREF_ACCOUNT_NAME, null);
        if(accountName == null){
            Log.i(Constants.LOG_TAG, "Cannot send message. No account name found");
        }
        else {
            GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
                    "server:client_id:" + Constants.ANDROID_AUDIENCE);
            credential.setSelectedAccountName(accountName);
            Messaging.Builder builder = new Messaging.Builder(AndroidHttp.newCompatibleTransport(),
                    new GsonFactory(), credential)
                    .setRootUrl(Constants.SERVER_URL);

            messagingService = builder.build();
        }
    }
    return messagingService;
}
 
開發者ID:google,項目名稱:watchpresenter,代碼行數:22,代碼來源:MessagingService.java

示例3: sync

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
private static void sync(Context context, boolean fullSync) {
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
  GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
      "server:client_id:988087637760-6rhh5v6lhgjobfarparsomd4gectmk1v.apps.googleusercontent.com");
  String accountName = preferences.getString(PREF_ACCOUNT_NAME, null);
  if (accountName == null || accountName.isEmpty()) {
    // If you haven't set up an account yet, then we can't sync anyway.
    Log.w(TAG, "No account set, cannot sync!");
    return;
  }

  boolean hasGetAccountsPermission = ContextCompat.checkSelfPermission(
      context, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED;
  if (!hasGetAccountsPermission) {
    Log.w(TAG, "Don't have GET_ACCOUNTS permission, can't sync.");
    return;
  }

  Log.d(TAG, "Using account: " + accountName);
  credential.setSelectedAccountName(accountName);

  Syncsteps.Builder builder = new Syncsteps.Builder(
      AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential);
  builder.setApplicationName("Steptastic");
  new StepSyncer(context, builder.build(), fullSync).sync();
}
 
開發者ID:codeka,項目名稱:steptastic,代碼行數:27,代碼來源:StepSyncer.java

示例4: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Subclasses may override this to execute initialization of the activity.
 * If it uses any CloudBackend features, it should be executed inside
 * {@link #onCreateFinished()} that will be called after CloudBackend
 * initializations such as user authentication.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // init backend
    mCloudBackend = new CloudBackendMessaging(getActivity());

    // create credential
    mCredential = GoogleAccountCredential.usingAudience(getActivity(), Consts.AUTH_AUDIENCE);
    mCloudBackend.setCredential(mCredential);

    signInAndSubscribe(false);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMsgReceiver,
            new IntentFilter(GCMIntentService.BROADCAST_ON_MESSAGE));
}
 
開發者ID:pkill9,項目名稱:POSproject,代碼行數:23,代碼來源:CloudBackendFragment.java

示例5: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Subclasses may override this to execute initialization of the activity.
 * If it uses any CloudBackend features, it should be executed inside
 * {@link #onCreateFinished()} that will be called after CloudBackend
 * initializations such as user authentication.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);

    // init backend
    mCloudBackend = new CloudBackendMessaging(getActivity());

    // create credential
    mCredential = GoogleAccountCredential.usingAudience(getActivity(), Consts.AUTH_AUDIENCE);
    mCloudBackend.setCredential(mCredential);

    signInAndSubscribe(false);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMsgReceiver,
            new IntentFilter(GCMIntentService.BROADCAST_ON_MESSAGE));
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:24,代碼來源:CloudBackendFragment.java

示例6: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Called when the activity is first created. It displays the UI, checks
 * for the account previously chosen to sign in (if available), and
 * configures the service object.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  settings = getSharedPreferences(TAG, 0);
  credential = GoogleAccountCredential.usingAudience(this, ClientCredentials.AUDIENCE);
  setAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

  Tictactoe.Builder builder = new Tictactoe.Builder(
      AndroidHttp.newCompatibleTransport(), new GsonFactory(),
      credential);
  service = builder.build();

  if (credential.getSelectedAccountName() != null) {
    onSignIn();
  }

  Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-endpoints-tictactoe-android,代碼行數:26,代碼來源:TictactoeActivity.java

示例7: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    CloudBackendMessaging cloudBackend = getCloudBackend();

    // create credential
    credential = GoogleAccountCredential.usingAudience(this, Consts.AUTH_AUDIENCE);
    cloudBackend.setCredential(credential);

    // get account name from the shared pref
    String accountName = PreferenceManager.getDefaultSharedPreferences(this).getString(PREF_KEY_ACCOUNT_NAME, null);
    if (accountName == null) {
        // let user pick an account
        startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
        return; // continue init in onActivityResult
    } else {
        credential.setSelectedAccountName(accountName);
    }

    mEditText = (EditText) findViewById(R.id.edit_text);
    mSendBtn = findViewById(R.id.send_btn);
}
 
開發者ID:yanzm,項目名稱:MobileBackendStarter,代碼行數:25,代碼來源:MainActivity.java

示例8: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	state = ((GlobalState) getApplicationContext());

	settings = this.getSharedPreferences("prefs", 0);

	accountName = settings.getString(PREF_ACCOUNT_NAME, null);

	if (accountName == null) {
		credential = GoogleAccountCredential.usingAudience(this,
				"server:client_id:" + WEB_CLIENT_ID);
		startActivityForResult(credential.newChooseAccountIntent(),
				REQUEST_ACCOUNT_PICKER);
	} else {
		credential = GoogleAccountCredential.usingAudience(this,
				"server:client_id:" + WEB_CLIENT_ID);
		credential.setSelectedAccountName(accountName);
	}

	setContentView(R.layout.activity_list_add);

	progress = new ProgressDialog(this);

}
 
開發者ID:sajiddalvi,項目名稱:guruslist,代碼行數:26,代碼來源:ListAddActivity.java

示例9: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	state = ((GlobalState) getApplicationContext());
       settings = this.getSharedPreferences("prefs", 0);

	setContentView(R.layout.activity_message_add);
	
       Bundle b = getIntent().getExtras();
 
       convId = b.getLong("convId");

       accountName = settings.getString(PREF_ACCOUNT_NAME, null);
	
       if (accountName == null) {
       	credential = GoogleAccountCredential.usingAudience(this,"server:client_id:" + WEB_CLIENT_ID);
       	startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
       } else {
   		credential = GoogleAccountCredential.usingAudience(this,"server:client_id:" + WEB_CLIENT_ID);
           credential.setSelectedAccountName(accountName);
       }
       
	progress = new ProgressDialog(this);

}
 
開發者ID:sajiddalvi,項目名稱:guruslist,代碼行數:26,代碼來源:MessageAddActivity.java

示例10: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = getSharedPreferences(Constants.SETTINGS_NAME, MODE_PRIVATE);
    registered = settings.getBoolean(Constants.PREF_REGISTERED, false);
    vibration = settings.getBoolean(Constants.PREF_VIBRATION, true);
    credential = GoogleAccountCredential.usingAudience(this,
            "server:client_id:" + Constants.ANDROID_AUDIENCE);
    setSelectedAccountName(settings.getString(Constants.PREF_ACCOUNT_NAME, null));
    if (credential.getSelectedAccountName() != null) {
        Log.d(Constants.LOG_TAG, "User already logged in");
    } else {
        Log.d(Constants.LOG_TAG, "User not logged in. Requesting user...");
        launchChooseAccount();
    }
    try {
        versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
        versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        Log.d(Constants.LOG_TAG, "Pagage name: " + getPackageName());
        Log.d(Constants.LOG_TAG, "Version code: " + versionCode);
        Log.d(Constants.LOG_TAG, "Version name: " + versionName);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(Constants.LOG_TAG, "Cannot retrieve app version", e);
    }
    registerReceiver(broadcastReceiver, new IntentFilter(ACTION_STOP_MONITORING));

    wearController = new WearController(this);



}
 
開發者ID:google,項目名稱:watchpresenter,代碼行數:32,代碼來源:MainActivity.java

示例11: getCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Retrieve a GoogleAccountCredential used to authorise requests made to the cloud endpoints
 * backend.
 *
 * @param context application context
 * @param accountName the account selected
 * @return
 */
public static GoogleAccountCredential getCredential(Context context, String accountName) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
            "server:client_id:" + Constants.SERVER_CLIENTID);
    // Small workaround to avoid setting an account that doesn't exist, so we can test.
    if (!TEST_EMAIL_ADDRESS.equals(accountName)) {
        credential.setSelectedAccountName(accountName);
    }
    return credential;
}
 
開發者ID:blynch,項目名稱:CloudMemeAndroid,代碼行數:18,代碼來源:Constants.java

示例12: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Subclasses may override this to execute initialization of the activity. If
 * it uses any CloudBackend features, it should be executed inside
 * {@link #onPostCreate()} that will be called after CloudBackend
 * initializations such as user authentication.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // init backend
  cloudBackend = new CloudBackendMessaging(this);

  // create credential
  credential = GoogleAccountCredential.usingAudience(this, Consts.AUTH_AUDIENCE);
  cloudBackend.setCredential(credential);

  // if auth enabled, get account name from the shared pref
  if (isAuthEnabled()) {
    String accountName = getPreferencesAccountName();
    if (accountName == null) {
      // let user pick an account
      super.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
      return; // continue init in onActivityResult
    } else {
      credential.setSelectedAccountName(accountName);
    }
  }

  // post create initialization
  _onPostCreate();
}
 
開發者ID:EnteriseToolkit,項目名稱:codetalk,代碼行數:33,代碼來源:CloudBackendSherlockFragmentActivity.java

示例13: buildServiceHandler

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Build and returns an instance of {@link com.appspot.udacity_extras.conference.Conference}
 *
 * @param context
 * @param email
 * @return
 */
public static com.appspot.udacity_extras.conference.Conference buildServiceHandler(
        Context context, String email) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(
            context, AppConstants.AUDIENCE);
    credential.setSelectedAccountName(email);

    com.appspot.udacity_extras.conference.Conference.Builder builder
            = new com.appspot.udacity_extras.conference.Conference.Builder(
            AppConstants.HTTP_TRANSPORT,
            AppConstants.JSON_FACTORY, credential);
    builder.setApplicationName("conference-central-server");
    return builder.build();
}
 
開發者ID:udacity,項目名稱:conference-central-android-app,代碼行數:21,代碼來源:ConferenceUtils.java

示例14: isSignedIn

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Retrieves the previously used account name from the application preferences and checks if the
 * credential object can be set to this account.
 */
private boolean isSignedIn() {
  credential = GoogleAccountCredential.usingAudience(this, AUDIENCE);
  SharedPreferences settings = getSharedPreferences("MobileAssistant", 0);
  String accountName = settings.getString(ACCOUNT_NAME_SETTING_NAME, null);
  credential.setSelectedAccountName(accountName);

  return credential.getSelectedAccount() != null;
}
 
開發者ID:googlearchive,項目名稱:solutions-mobile-shopping-assistant-android-client,代碼行數:13,代碼來源:SignInActivity.java

示例15: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Subclasses may override this to execute initialization of the activity. If
 * it uses any CloudBackend features, it should be executed inside
 * {@link #onPostCreate()} that will be called after CloudBackend
 * initializations such as user authentication.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // init backend
  cloudBackend = new CloudBackendMessaging(this);

  // create credential
  credential = GoogleAccountCredential.usingAudience(this, Consts.AUTH_AUDIENCE);
  cloudBackend.setCredential(credential);

  // if auth enabled, get account name from the shared pref
  if (isAuthEnabled()) {
    String accountName = cloudBackend.getSharedPreferences().getString(PREF_KEY_ACCOUNT_NAME,
        null);
    if (accountName == null) {
      // let user pick an account
      super.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
      return; // continue init in onActivityResult
    } else {
      credential.setSelectedAccountName(accountName);
    }
  }

  // post create initialization
  _onPostCreate();
}
 
開發者ID:harrypritchett,項目名稱:Give-Me-Ltc-Android-App,代碼行數:34,代碼來源:CloudBackendActivity.java


注:本文中的com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.usingAudience方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。