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에 감사드립니다.