예제 #1
0
  /**
   * Gets the currently-logged in user's Google Calendar, or the Google Calendar for the user
   * specified in the given intent's {@link #EXTRA_ACCOUNT_NAME}.
   */
  private long getCalendarId(Intent intent) {
    final String accountName;
    if (intent != null && intent.hasExtra(EXTRA_ACCOUNT_NAME)) {
      accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME);
    } else {
      accountName = AccountUtils.getActiveAccountName(this);
    }

    if (TextUtils.isEmpty(accountName)) {
      return INVALID_CALENDAR_ID;
    }

    // TODO: The calendar ID should be stored in shared settings_prefs upon choosing an account.
    Cursor calendarsCursor =
        getContentResolver()
            .query(
                CalendarContract.Calendars.CONTENT_URI,
                new String[] {"_id"},
                // TODO: What if the calendar is not displayed or not sync'd?
                "account_name = ownerAccount and account_name = ?",
                new String[] {accountName},
                null);

    long calendarId = INVALID_CALENDAR_ID;
    if (calendarsCursor != null && calendarsCursor.moveToFirst()) {
      calendarId = calendarsCursor.getLong(0);
      calendarsCursor.close();
    }

    return calendarId;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_debug_action_showdrivefiles);
    mLogArea = (TextView) findViewById(R.id.logArea);

    mProgressDialog = new ProgressDialog(this);
    mGoogleApiClient =
        new Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_APPFOLDER)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .setAccountName(AccountUtils.getActiveAccountName(this))
            .build();
  }