当前位置: 首页>>代码示例>>Java>>正文


Java GoogleAccountCredential.setSelectedAccountName方法代码示例

本文整理汇总了Java中com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.setSelectedAccountName方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleAccountCredential.setSelectedAccountName方法的具体用法?Java GoogleAccountCredential.setSelectedAccountName怎么用?Java GoogleAccountCredential.setSelectedAccountName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential的用法示例。


在下文中一共展示了GoogleAccountCredential.setSelectedAccountName方法的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: getGoogleTasksService

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
public static Tasks getGoogleTasksService(final Context context, String accountName) {
    final GoogleAccountCredential credential =
            GoogleAccountCredential.usingOAuth2(context, ListManager.TASKS_SCOPES);
    credential.setSelectedAccountName(accountName);
    Tasks googleService =
        new Tasks.Builder(TRANSPORT, JSON_FACTORY, credential)
                 .setApplicationName(DateUtils.getAppName(context))
                 .setHttpRequestInitializer(new HttpRequestInitializer() {
                     @Override
                     public void initialize(HttpRequest httpRequest) {
                         credential.initialize(httpRequest);
                         httpRequest.setConnectTimeout(3 * 1000);  // 3 seconds connect timeout
                         httpRequest.setReadTimeout(3 * 1000);  // 3 seconds read timeout
                     }
                 })
                 .build();
    return googleService;
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:19,代码来源:Reminders.java

示例3: 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

示例4: 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

示例5: checkGmailApiRequirements

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
private void checkGmailApiRequirements() {


        String accountName = PreferenceManager.getDefaultSharedPreferences(getContext())
                .getString(PREF_ACCOUNT_NAME, null);

        if (accountName != null) {
            GoogleAccountCredential mCredential = GoogleAccountCredential.usingOAuth2(
                    getContext().getApplicationContext(), Arrays.asList(SCOPES))
                    .setBackOff(new ExponentialBackOff());
            mCredential.setSelectedAccountName(accountName);

            if (!DeviceUtils.isGooglePlayServicesAvailable(getContext())) {
                DeviceUtils.acquireGooglePlayServices(getContext());
            }
            else{
                mService = new Gmail.Builder(
                        AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), mCredential)
                        .setApplicationName(AppUtils.getApplicationName(getContext()))
                        .build();
                authorized = true;
            }


        } else {
            GmailAuthorizationActivity.setListener(this);
            getContext().startActivity(new Intent(getContext(), GmailAuthorizationActivity.class));
        }

    }
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:31,代码来源:BaseGmailProvider.java

示例6: createDriveService

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
private Drive createDriveService(String accountName, Context appContext) {
	logDebug("createDriveService "+accountName);
	GoogleAccountCredential credential = createCredential(appContext);
	credential.setSelectedAccountName(accountName);

	return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
	.setApplicationName(getApplicationName())
	.build();
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:10,代码来源:GoogleDriveFileStorage.java

示例7: create

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:33,代码来源:GoogleDriveClient.java

示例8: create

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
public static Drive create(Context context) throws IOException, GoogleAuthException, ImportExportException {
    String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:34,代码来源:GoogleDrivePictureClient.java

示例9: buildGoogleAccountCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
/**
 * Build the credential to authorize the installed application to access user's protected data.
 */
private GoogleAccountCredential buildGoogleAccountCredential() throws Exception {
 GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(activity, scopes);
    credential.setBackOff(new ExponentialBackOff());
    credential.setSelectedAccountName(selectedGoogleAccount);
    return credential;
}
 
开发者ID:jayxue,项目名称:YouTubeUploader,代码行数:10,代码来源:YouTubeUploadTask.java

示例10: getGoogleAccountCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
/**
 * Gets the google account credential.
 * 
 * @param context the context
 * @param accountName the account name
 * @param scope the scope
 */
public static GoogleAccountCredential getGoogleAccountCredential(
    Context context, String accountName, String scope) throws IOException, GoogleAuthException {
  GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
  credential.setSelectedAccountName(accountName);
  credential.getToken();
  return credential;
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:15,代码来源:SendToGoogleUtils.java

示例11: authorise

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
private void authorise(final String accountName, final int requestCode,
                       final IfAlreadyAuthorised ifAlreadyAuthorised, final ImageButton syncButton) {
    if (!isAccountAuthorised(accountName)) {
        final Activity activity = getActivity();
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(activity, TASKS_SCOPES);
        credential.setSelectedAccountName(accountName);
        final Tasks googleService =
                new Tasks.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
                        .setApplicationName(DateUtils.getAppName(activity)).build();
        new Thread(new Runnable() {
            public void run() {
                try {
                    googleService.tasklists().list().execute();
                    saveAuthorisationForAccount(accountName);
                    isSyncWithGTasksEnabled = true;
                    ifAlreadyAuthorised.doAction();
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            syncButton.setVisibility(View.VISIBLE);
                        }
                    });
                } catch (UserRecoverableAuthIOException userRecoverableException) {
                    startActivityForResult(userRecoverableException.getIntent(), requestCode);
                } catch (IOException e) {
                    Log.e(LOGTAG, "authorise() :: cannot contact google servers for account +\""
                            + accountName + "\"", e);
                }
            }
        }).start();
    } else
        ifAlreadyAuthorised.doAction();
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:34,代码来源:ListManager.java

示例12: create

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_select_error);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account) +" " + googleDriveAccount)
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
开发者ID:emmanuel-florent,项目名称:flowzr-android-black,代码行数:33,代码来源:GoogleDriveClient.java

示例13: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    try {
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(mActivity, Collections.singleton(TasksScopes.TASKS));
        credential.setSelectedAccountName(mEmail);

        // Build Tasks service object
        Tasks service = new Tasks.Builder(httpTransport, jsonFactory, credential).setApplicationName(mActivity.getString(R.string.app_name)).build();

        // Gets list of user's task lists
        List<TaskList> taskLists = service.tasklists().list().execute().getItems();

        // Gets default list
        String firstTaskListId = taskLists.get(0).getId();

        // Gets tasks from default list
        List<Task> tasks = service.tasks().list(firstTaskListId).execute().getItems();

        DatabaseHelper dbHelper = new DatabaseHelper(mActivity);

        // Loop through selected tasks, deleting each from default list
        for (int i = 0; i < mSelectedItemIds.size(); i++) {
            Task task = tasks.get(mSelectedItemIds.keyAt(i));
            dbHelper.deleteTask(task.getId());
            service.tasks().delete(firstTaskListId, task.getId()).execute();
        }

        dbHelper.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jakemoritz,项目名称:Tasking,代码行数:34,代码来源:DeleteTasksTask.java

示例14: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    try {
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(mActivity, Collections.singleton(TasksScopes.TASKS));
        credential.setSelectedAccountName(mEmail);

        // Build Tasks service object
        Tasks service = new Tasks.Builder(httpTransport, jsonFactory, credential).setApplicationName(mActivity.getString(R.string.app_name)).build();

        // Gets list of user's task lists
        List<TaskList> taskLists = service.tasklists().list().execute().getItems();

        // Gets default list
        String firstTaskListId = taskLists.get(0).getId();

        // Insert task into default list
        service.tasks().insert(firstTaskListId, task).execute();

        // Save new task to database
        DatabaseHelper dbHelper = new DatabaseHelper(mActivity);
        dbHelper.insertTask(task);
        dbHelper.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jakemoritz,项目名称:Tasking,代码行数:29,代码来源:AddTaskTask.java

示例15: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    try {
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(mActivity, Collections.singleton(TasksScopes.TASKS));
        credential.setSelectedAccountName(mEmail);

        // Build Tasks service object
        Tasks service = new Tasks.Builder(httpTransport, jsonFactory, credential).setApplicationName(mActivity.getString(R.string.app_name)).build();

        // Gets list of user's task lists
        List<TaskList> taskLists = service.tasklists().list().execute().getItems();

        // Gets default list
        String firstTaskListId = taskLists.get(0).getId();

        // Gets tasks from default task list
        tasks = service.tasks().list(firstTaskListId).execute().getItems();

        if (tasks != null) {
            // Removes empty task
            Task emptyTask = tasks.get(tasks.size() - 1);
            if (emptyTask.getTitle().length() == 0 && emptyTask.getNotes() == null) {
                tasks.remove(tasks.size() - 1);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jakemoritz,项目名称:Tasking,代码行数:31,代码来源:GetTasksTask.java


注:本文中的com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.setSelectedAccountName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。