2012-03-20 8 views
2

안드로이드에서 .vcf 파일을 가져오고 있지만 중복 된 레코드를 가져옵니다.안드로이드 연락처에서 중복 가져 오기

코드 :

public void doImport(final String fileName, final boolean replace) { 
    try { 

      File vcfFile = new File(fileName); 

      final BufferedReader vcfBuffer = new BufferedReader(new FileReader(fileName)); 



      final long maxlen = vcfFile.length(); 

    // Start lengthy operation in a background thread 
      new Thread(new Runnable() { 
     public void run() { 
      long importStatus = 0; 

      synchronized (syncMonitor) { 
        mAction = Action.IMPORT; 
        syncFileName = fileName; 
        } 

      SQLiteDatabase db = mOpenHelper.getWritableDatabase(); 
      SQLiteStatement querySyncId = db.compileStatement("SELECT " + SYNCID + " FROM " + SYNCDATA_TABLE_NAME + " WHERE " + PERSONID + "=?"); 
      SQLiteStatement queryPersonId = db.compileStatement("SELECT " + PERSONID + " FROM " + SYNCDATA_TABLE_NAME + " WHERE " + SYNCID + "=?"); 
      SQLiteStatement insertSyncId = db.compileStatement("INSERT INTO " + SYNCDATA_TABLE_NAME + " (" + PERSONID + "," + SYNCID + ") VALUES (?,?)"); 
      Contact parseContact = new Contact(querySyncId, queryPersonId, insertSyncId); 
        try { 
          long ret = 0; 
          do { 
            ret = parseContact.parseVCard(vcfBuffer); 
            if (ret >= 0) { 
              parseContact.addContact(getApplicationContext(), 0, replace); 
              importStatus += parseContact.getParseLen(); 

              // Update the progress bar 
         // app.updateProgress((int) (100 * importStatus/maxlen)); 
            } 
          } while (ret > 0); 

          db.close(); 
         // app.updateProgress(100); 
        synchronized (syncMonitor) { 
          mAction = Action.IDLE; 
          // showNotification(); 
        } 
       // stopSelf(); 
        } catch (IOException e) { 
        } 
     } 
    }).start(); 


    } catch (FileNotFoundException e) { 
     // app.updateStatus("File not found: " + e.getMessage()); 
    } 
    Toast.makeText(mContext, "Import", Toast.LENGTH_LONG).show(); 

    } 

    private static class DatabaseHelper extends SQLiteOpenHelper { 

     DatabaseHelper(Context context) { 
      super(context, DATABASE_NAME, null, DATABASE_VERSION); 
     } 

     @Override 
     public void onCreate(SQLiteDatabase db) { 
      db.execSQL("CREATE TABLE " + SYNCDATA_TABLE_NAME + " (" 
        + PERSONID + " INTEGER PRIMARY KEY," 
        + SYNCID + " TEXT UNIQUE" 
        +");"); 
     } 

       @Override 
       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
         // No need to do anything --- this is version 1 

       } 
    } 

Contact.java : Click here Contact.java

코드 링크 : 수입 접촉 FO 방법 위의 코드에서 중복을 가져 제한하는 방법 Click here to get whole code of contact import and export

Adv에 감사드립니다.

답변

0

VCard의 "X-IRMC-LUID"필드가 주소록에 저장된 필드와 동일하지 않은지 확인해야합니다. 동일하다면 VCard 항목은 복제본입니다.

이러한 필드를 생성하는 방법에 대한 사양이 없으며 대부분 AFAIK가 여러 가지 방법으로 수행됩니다. 대부분이 UID 필드 또는 VCard의 위치를 ​​복제합니다. 이 오픈 소스 앱에는 유용한 코드 예제가 포함되어 있습니다. http://code.google.com/p/vcardio/

관련 문제