mangstadt / ez-vcard-android

Maps the Android vCard API to the ez-vcard API.
BSD 3-Clause "New" or "Revised" License
29 stars 7 forks source link

Street and Number in wrong order #7

Open skauss opened 4 years ago

skauss commented 4 years ago

Hi I am new to vcard. In Germany we use "Street Number" like "Engestrasse 2". On my phone contact on an pixel 3 I enter "Engestrasse 2" but get back "2 Engestrasse". Any idea how to solve this. US address use "323 Street" German address use "Street 123"

I read the contract like this :

cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
    cursor.moveToFirst();
     for (int i = 0; i < cursor.getCount(); i++) {
          String vCardStr = getVcardAsString(cr, cursor);
          cursor.moveToNext();
         VCard vcard = Ezvcard.parse(vCardStr).first();
...
    }
}
...
public String getVcardAsString(ContentResolver cr, Cursor cursor) {
        //cursor.moveToFirst();
        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
        AssetFileDescriptor fd;
        try {
            fd = cr.openAssetFileDescriptor(uri, "r");
            FileInputStream fis = fd.createInputStream();
            byte[] buf = new byte[(int) fis.available()];
            fis.read(buf);
            return new String(buf);
        } catch (Exception ex) {
            Log.d(TAG,"read vcard", ex);
        }
        return "";
    }

Regards

mangstadt commented 4 years ago

Hello,

You would need to obtain the street address portion of the address property, and then convert the street address using Java string manipulation.

VCard vcard = Ezvcard.parse(vCardStr).first();
String street = vcard.getAddress().getStreetAddress();
String germanStreet = convertToGermanFormat(street);
vcard.getAddress().setStreetAddress(germanStreet);
skauss commented 4 years ago

It looks for me "Street Number" is country dependent. Germany : "Street Number" US : "Number Street" And I am wondering that I the one who has the problem to rotate "Street Number" on country code ?

mangstadt commented 4 years ago

You're the first person to bring this to my attention. :)