本文整理汇总了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();
}
示例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;
}
示例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();
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}