示例#1
0
  /**
   * Searches a fusion table in user's Google tables.
   *
   * @param tableName name of fusion table to search
   * @param context android context
   * @param accountName name of account
   * @param isDelete whether delete this track
   * @return true means find and delete fusion table
   */
  public static boolean searchFusionTableByTitle(
      String tableName, Context context, String accountName, boolean isDelete) {
    try {
      GoogleAccountCredential credential =
          SendToGoogleUtils.getGoogleAccountCredential(
              context, accountName, SendToGoogleUtils.FUSION_TABLES_SCOPE);
      if (credential == null) {
        return false;
      }
      Fusiontables fusiontables =
          new Fusiontables.Builder(
                  AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
              .build();
      List<Table> tables = fusiontables.table().list().execute().getItems();
      for (Iterator<Table> iterator = tables.iterator(); iterator.hasNext(); ) {
        Table table = (Table) iterator.next();
        String title = table.getName();
        if (title.equals(tableName)) {
          if (isDelete) {
            fusiontables.table().delete(table.getTableId()).execute();
          }
          return true;
        }
      }

    } catch (Exception e) {
      Log.d(EndToEndTestUtils.LOG_TAG, "Failed when operate fusion table.", e);
    }
    return false;
  }
 //	----------------------------------------------------------------------------------------------------------------
 //      Method:     GetTableId
 //      Inputs:	    none
 //     Outputs:	    none
 // Description:     Get Table ID from Table Nam
 //	----------------------------------------------------------------------------------------------------------------
 private static String GetTableId(String tableName) throws IOException {
   String tid = null; // Set default return
   System.out.println("Get Table ID: " + tableName); // Print header
   // Get the table list
   Fusiontables.Table.List listTables = FusionTables.table().list();
   TableList tablelist = listTables.execute(); //
   // If there are no tables, print that info
   if (tablelist.getItems() == null || tablelist.getItems().isEmpty()) { //
     System.out.println("No tables found!"); //
   } //
   else // Else, loop through tables, find match
   { // If it matches then save the table ID
     for (Table table : tablelist.getItems()) //
     { //
       if (table.getName().equals(tableName)) tid = table.getTableId();
     } // Printout the results of that
     System.out.println(tableName + " - tableId: " + tid); //
   } //
   return tid; // Return the table ID
 }