Example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingAudience

List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingAudience

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingAudience.

Prototype

public static GoogleAccountCredential usingAudience(Context context, String audience) 

Source Link

Document

Sets the audience scope to use with Google Cloud Endpoints.

Usage

From source file:com.zuluindia.watchpresenter.messaging.MessagingService.java

License:Open Source License

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 {//  w  w  w  . j a v  a  2  s.c  o  m
            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;
}

From source file:comp3111h.anytaxi.customer.RequestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_request);

    //Identity user's identity, used to communicate with the server
    LocationUtils.credential = GoogleAccountCredential.usingAudience(this,
            "server:client_id:" + LocationUtils.WEB_CLIENT_ID);
    startActivityForResult(LocationUtils.credential.newChooseAccountIntent(),
            LocationUtils.REQUEST_ACCOUNT_PICKER);

    // Get handles to the UI view objects
    mLatLng = (TextView) findViewById(R.id.lat_lng);
    mAddress = (TextView) findViewById(R.id.address);
    mActivityIndicator = (ProgressBar) findViewById(R.id.address_progress);
    mConnectionState = (TextView) findViewById(R.id.text_connection_state);
    mConnectionStatus = (TextView) findViewById(R.id.text_connection_status);

    LocationUtils.mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    LocationUtils.mMap.setMyLocationEnabled(true);

    // Create a new global location parameters object
    mLocationRequest = LocationRequest.create();

    /*/*  w ww .j  a  v  a 2 s  . c  o m*/
     * Set the update interval
     */
    mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);

    // Use high accuracy
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    // Set the interval ceiling to one minute
    mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    // Note that location updates are off until the user turns them on
    mUpdatesRequested = true;

    // Open Shared Preferences
    mPrefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);

    // Get an editor
    mEditor = mPrefs.edit();

    /*
     * Create a new location client, using the enclosing class to
     * handle callbacks.
     */
    mLocationClient = new LocationClient(this, this, this);
}

From source file:comp3111h.anytaxi.driver.Register_FormFragment.java

@Override
public void onStart() {
    super.onStart();

    Log.i(TAG, "User is filling the registration form.");

    credential = GoogleAccountCredential.usingAudience(getActivity(), Utils.AUDIENCE);
}

From source file:io.pacmonitorandroid.app.google.cloud.core.CloudBackendFragment.java

License:Apache License

/**
 * 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.
 *//*from w w  w  .j  av  a2s  .  com*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // init backend
    mCloudBackend = new CloudBackendPatient(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));
}