1
votes

I am new to this so please pardon my code (make suggestions please)

I am attempting to create an app that adds a new contact given a set of data and completely updates every field within the contact that is relevant for an employer or employee.

I understand that information can be grabbed from intents, and require a specific key to acquire that information.

I understand I can use Intents.Intent.NAME and other similar constants for the keys for more generic fields. I've noticed these constants are all lowercase and are exactly what you'd expect. Intents.Intent.NAME returns "name". I've read that this is a convention that has been followed for android programming.

When attempting to update the address, for instance, I use Intents.Intent.POSTAL as the key and a string for an address containing the street, city, state, zip, and country in that order. This will update all of this information into the "Street" field.

I've tried many strings that would be reasonable keys for the city, state, etc. and none of them seem to work. I've also tried inputting "\n" between the street, city, state, zip, and country strings to see if they would automatically jump to the next text field (as a workaround). Unfortunately, the "Street" field is a multiline field and this does not work either.

Even when trying to update prefixes and suffixes for a person's name, reasonable strings to serve as the keys do not seem to work.

Overall, I am having trouble updating the following fields as I do not know their respective keys:

  • Prefix (part of the "Name" category)
  • Suffix (part of the "Name" category)
  • Web Address ("More Items")
  • Date / Events ("More Items")
  • City / State / Zip / Country ("Address" category)

Here is my code currently, I have it set to apply this method to the click of a button. I have provided many test cases to show my point. I cannot find the key needed to update these fields. If there are any ways to gather information about where the fields check for data when updating from an intent, do let me know. If there is another way to more flawlessly update the contact information, please let me know. THANK YOU for your help!

Intent insertIntent = new Intent(Intents.Insert.ACTION);
            insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
            insertIntent.putExtra("name", "This T. Works");
            insertIntent.putExtra("name_given", "Thiss");
            insertIntent.putExtra("name_middle", "Doess");
            insertIntent.putExtra("name_family", "Nott");

            // All working properly
            insertIntent.putExtra(ContactsContract.Intents.Insert.EMAIL, "[email protected]");
            insertIntent.putExtra(ContactsContract.Intents.Insert.PHONE, "(098) 765-4321");
            insertIntent.putExtra(ContactsContract.Intents.Insert.COMPANY, "TEST INC.");
            insertIntent.putExtra(Intents.Insert.SECONDARY_PHONE, "(123) 456-7890");
            insertIntent.putExtra(Intents.Insert.JOB_TITLE, "Tester");
            insertIntent.putExtra(Intents.Insert.IM_HANDLE, "@tester");

            // Not working at all... No "City" constant
            insertIntent.putExtra("postal_city", "Testopolis1");
            insertIntent.putExtra("city", "Testopolis2");
            insertIntent.putExtra("City", "Testopolis3");

            // Not working at all... No "State" constant
            insertIntent.putExtra("postal_state", "Testopolis1");
            insertIntent.putExtra("state", "Testopolis2");
            insertIntent.putExtra("State", "Testopolis3");

            // Not working at all... No "Zip" constant
            insertIntent.putExtra("zip", "12345");
            insertIntent.putExtra("ZIP", "11231");
            insertIntent.putExtra("Zip", "12134");
            insertIntent.putExtra("zipcode", "12314");
            insertIntent.putExtra("zip_code", "12341");
            insertIntent.putExtra("zipCode", "12434");
            insertIntent.putExtra("postal_code", "14234");
            insertIntent.putExtra("post_code", "11234");
            insertIntent.putExtra("postCode", "12234");
            insertIntent.putExtra("postalCode", "12334");
            insertIntent.putExtra("postalcode", "12344");

            // The "Postal" constant that puts everything into the "Street" field
            insertIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "1234 TestRun Drive\n Testopolis5\n Testerland\n 55421\n USA");
            startActivity(insertIntent);
1

1 Answers

0
votes

You can create a data class that implements the Parcelable interface. After that, You can move entire objects from one activity to another, retaining all class methods and abilities.

For example,

First, Create a data class that implements Parcelable.

public class Property implements Parcelable {
  ...
}

Inside the first activity create your intent object and use the putExtra method to add the whole class as an extra.

Intent intent = new Intent(MainActivity.this, DetailActivity.class);
intent.putExtra("Property", property);
startActivity(intent);

Now that you’re in the second activity you need to collect the intent object and extract the property class that’s been converted into a parcel.

//collect our intent
Intent intent = getIntent();
Property property = intent.getParcelableExtra("Property");

Checkout tutorial Transfer Data between Activities with Android Parcelable for more details.