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.google.training.cpd200.conference.android.utils.ConferenceUtils.java

License:Open Source License

/**
 * Build and returns an instance of {@link com.appspot.cpd200_extras.conference.Conference}
 *
 * @param context//from   w  w w  .  ja  v a 2 s .co  m
 * @param email
 * @return
 */
public static com.appspot.cpd200_extras.conference.Conference buildServiceHandler(Context context,
        String email) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context, AppConstants.AUDIENCE);
    credential.setSelectedAccountName(email);

    com.appspot.cpd200_extras.conference.Conference.Builder builder = new com.appspot.cpd200_extras.conference.Conference.Builder(
            AppConstants.HTTP_TRANSPORT, AppConstants.JSON_FACTORY, credential);
    builder.setApplicationName("conference-central-server");
    return builder.build();
}

From source file:com.lumysoft.lumyd.MainActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mUser = new User();
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);

    String userName = mSettings.getString(SettingsActivity.KEY_PREF_NAME, "");
    if (userName == "") {
        startActivity(new Intent(this, SettingsActivity.class));
    }/*from  w w  w  .  j a v  a2s .c om*/

    //Set up location request params
    mLRequest = LocationRequest.create();
    mLRequest.setInterval(2000);
    mLRequest.setFastestInterval(1000);
    mLRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    mCredential = GoogleAccountCredential.usingAudience(this, "server:client_id:" + LumydUtils.APPENGINE_APPID);

    //Retrieve the account name for credentials
    String accountName = mSettings.getString(LumydUtils.PREF_ACCOUNT_NAME, null);
    if (accountName == null) {
        startActivityForResult(mCredential.newChooseAccountIntent(), LumydUtils.REQUEST_ACCOUNT_PICKER);
    } else {
        mCredential.setSelectedAccountName(accountName);
    }

    Userendpoint.Builder builder = new Userendpoint.Builder(AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), mCredential);
    mUserEndpoint = builder.build();

    mDistance = 100000; //TODO: Incremental depending on results

    //Register with Google Cloud Messaging
    mContext = getApplicationContext();
    mRegid = LumydUtils.getRegistrationId(mContext, mSettings);

    registerBackground();
    mGcm = GoogleCloudMessaging.getInstance(this);

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

From source file:com.meiste.tempalarm.sync.AccountUtils.java

License:Apache License

public static synchronized GoogleAccountCredential getCredential(final Context context) {
    if (sCredential == null) {
        sCredential = GoogleAccountCredential.usingAudience(context.getApplicationContext(),
                AppConstants.CLIENT_AUDIENCE);
        sCredential.setSelectedAccountName(AccountUtils.getAccountName(context));
    }//from   w  ww .j  a v  a 2 s.  co  m
    return sCredential;
}

From source file:com.piusvelte.cloudset.android.ActionsIntentService.java

License:Open Source License

private void publish(String action, List<Extra> extras) {
    SharedPreferences sp = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
    String accountName = sp.getString(CloudSetMain.PREFERENCE_ACCOUNT_NAME, null);
    Long deviceId = sp.getLong(CloudSetMain.PREFERENCE_DEVICE_ID, CloudSetMain.INVALID_DEVICE_ID);

    if (accountName != null && !deviceId.equals(CloudSetMain.INVALID_DEVICE_ID)) {
        Action publication = new Action();
        publication.setPublisher(deviceId);
        publication.setName(action);/*from   w  w w  . j  a v a  2s  .  c om*/
        publication.setExtras(extras);

        GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(this,
                "server:client_id:" + getString(R.string.android_audience));
        credential.setSelectedAccountName(accountName);

        Actionendpoint.Builder endpointBuilder = new Actionendpoint.Builder(
                AndroidHttp.newCompatibleTransport(), new JacksonFactory(), credential)
                        .setApplicationName(getString(R.string.app_name));
        endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();

        (new AsyncTask<Action, Void, Void>() {

            @Override
            protected Void doInBackground(Action... publications) {
                try {
                    endpoint.actionEndpoint().publish(publications[0]).execute();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                sWakeLock.release();
            }

        }).execute(publication);
    } else {
        sWakeLock.release();
    }
}

From source file:com.piusvelte.cloudset.android.DevicesLoader.java

License:Open Source License

private void initEndpoint(String account) {
    Context globalContext = getContext();
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(
            globalContext.getApplicationContext(),
            "server:client_id:" + globalContext.getString(R.string.android_audience));
    credential.setSelectedAccountName(account);
    Deviceendpoint.Builder endpointBuilder = new Deviceendpoint.Builder(AndroidHttp.newCompatibleTransport(),
            new JacksonFactory(), credential).setApplicationName(globalContext.getString(R.string.app_name));
    deviceendpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
}

From source file:com.piusvelte.cloudset.android.GCMIntentService.java

License:Open Source License

private Deviceendpoint getEndpoint(Context context) {
    if (endpoint == null) {
        String accountName = null;
        SharedPreferences sp = context.getSharedPreferences(context.getString(R.string.app_name), MODE_PRIVATE);

        if (sp.contains(CloudSetMain.PREFERENCE_ACCOUNT_NAME)) {
            accountName = sp.getString(CloudSetMain.PREFERENCE_ACCOUNT_NAME, null);
        }//from  w w w.ja v a  2s . c  o  m

        GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
                "server:client_id:" + context.getString(R.string.android_audience));
        credential.setSelectedAccountName(accountName);

        Deviceendpoint.Builder endpointBuilder = new Deviceendpoint.Builder(
                AndroidHttp.newCompatibleTransport(), new JacksonFactory(), credential)
                        .setApplicationName(getString(R.string.app_name));
        endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
    }

    return endpoint;
}

From source file:com.piusvelte.mosaic.android.MosaicService.java

License:Open Source License

private void loadMosaicUser() {
    if (mosaicUser != null)
        setNickname(mosaicUser.getNickname());
    else {/*from   w  ww.  j  av a2s.co m*/
        SharedPreferences sharedPreferences = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
        String accountName = sharedPreferences.getString(getString(R.string.preference_account_name), null);
        long user_id = sharedPreferences.getLong(getString(R.string.preference_user_id), Mosaic.INVALID_ID);
        if (accountName != null) {
            credential = GoogleAccountCredential.usingAudience(this,
                    "server:client_id:" + getString(R.string.client_id));
            credential.setSelectedAccountName(accountName);
            if (user_id != Mosaic.INVALID_ID)
                new GetUserTask(this, user_id).execute();
            else
                new InsertUserTask(this).execute();
        } else
            setNickname(null);
    }
}

From source file:com.taesua.admeet.admeet.ConferenceUtils.java

License:Open Source License

/**
 * Build and returns an instance of {@link com.appspot.ad_meet.conference.Conference}
 *
 * @param context//  www  .j  av  a 2 s . c o  m
 * @param email
 * @return
 */

public static com.appspot.ad_meet.conference.Conference buildServiceHandler(Context context, String email) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context, Ids.AUDIENCE);
    credential.setSelectedAccountName(email);

    com.appspot.ad_meet.conference.Conference.Builder builder = new com.appspot.ad_meet.conference.Conference.Builder(
            Ids.HTTP_TRANSPORT, Ids.JSON_FACTORY, credential);
    builder.setApplicationName("AdMeet");
    return builder.build();
}

From source file:com.udacity.devrel.training.conference.android.utils.ConferenceUtils.java

License:Open Source License

/**
 * Build and returns an instance of {@link com.appspot.your_app_id.conference.Conference}
 *
 * @param context/*from  w  w  w. j  a va 2 s  .c  o m*/
 * @param email
 * @return
 */
public static com.appspot.your_app_id.conference.Conference buildServiceHandler(Context context, String email) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context, AppConstants.AUDIENCE);
    credential.setSelectedAccountName(email);

    com.appspot.your_app_id.conference.Conference.Builder builder = new com.appspot.your_app_id.conference.Conference.Builder(
            AppConstants.HTTP_TRANSPORT, AppConstants.JSON_FACTORY, credential);
    builder.setApplicationName("conference-central-server");
    return builder.build();
}

From source file:com.zuluindia.watchpresenter.MainActivity.java

License:Open Source License

@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 {//from  ww  w .j a  v  a2 s  . c om
        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);

}