inserting email address into ContactMethods table in 0.9 beta

by kingkung » Sat, 30 Aug 2008 09:46:07 GMT


Sponsored Links
 For whatever reason, I'm having trouble inserting email addresses into
the ContactMethods table in 0.9... the code worked perfectly fine in
m5.

The insert() call is successful (no exception), but it consistently
says that 0 rows have been inserted.  These are the values that I set
in my ContentValues object:

cv = new ContentValues();
cv.put(ContactMethods.KIND,KIND_EMAIL); //KIND_EMAIL is an integer (1)
cv.put(ContactMethods.PERSON_ID, ac.mobileID); //long
cv.put(ContactMethods.DATA, email.value); //string
cv.put(ContactMethods.TYPE, email.type); //integer btwn 0-3
int rows =
context.getContentResolver().bulkInsert(getMethodUri(personUri),generateAddressCVarray(ac));
Logger.log(rows);

private static Uri getMethodUri(Uri contactUri)
{
        return
contactUri.buildUpon().appendPath(ContactMethods.CONTENT_URI.getLastPathSegment()).build();
}

Is there something I'm missing or something else that I need to set?
As I said before, this worked perfectly fine in m5.


--~--~---------~--~----~------------~-------~--~----~



inserting email address into ContactMethods table in 0.9 beta

by kingkung » Sat, 30 Aug 2008 09:50:17 GMT


 Slightly confusing code... the ContentValues properties (below) are
set in the method generateAddressCVarray(), which generates an array
of CVs for each email address...

cv = new ContentValues();
cv.put(ContactMethods.KIND,KIND_EMAIL); //KIND_EMAIL is an integer (1)
cv.put(ContactMethods.PERSON_ID, ac.mobileID); //long
cv.put(ContactMethods.DATA, email.value); //string
cv.put(ContactMethods.TYPE, email.type); //integer btwn 0-3

...........

The following line is then called for a bulkInsert... and the rows
always come out as 0.  Even if I insert them one at a time, I get the
same result.

int rows =
context.getContentResolver().bulkInsert(getMethodUri(personUri),generateAddressCVarray(ac));
Logger.log(rows);

private static Uri getMethodUri(Uri contactUri)
{
 return
contactUri.buildUpon().appendPath(ContactMethods.CONTENT_URI.getLastPathSegment()).build();
}

Can anyone help?
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


inserting email address into ContactMethods table in 0.9 beta

by Jeff Hamilton » Sat, 30 Aug 2008 09:54:14 GMT


 Does anything show up in the log when you see the failure?

-Jeff




--~--~---------~--~----~------------~-------~--~----~



inserting email address into ContactMethods table in 0.9 beta

by kingkung » Wed, 03 Sep 2008 01:21:31 GMT


 It's not a failure, it's just that 0 addresses are added.




--~--~---------~--~----~------------~-------~--~----~



inserting email address into ContactMethods table in 0.9 beta

by kingkung » Wed, 03 Sep 2008 04:09:11 GMT


 Never mind, my types are set to "0", and there is no "0" type anymore.





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Very Weird Spinner Issue

Hello,

I am trying (as many are doing) to populate a 2nd spinner out of the
first spinner selected item like this:

//populate first spinner
            final Spinner s = (Spinner) findViewById(R.id.spinner);
            ArrayAdapter adapter = ArrayAdapter.createFromResource(
                    this, R.array.universities,
android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
            s.setAdapter(adapter);

// Initialization of the 2nd spinner
                   String[] array = {"Select Building Here"};
                   final Spinner s2 = (Spinner) findViewById(R.id.spinner2);
                   ArrayAdapter<String> cadapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, array);
                   cadapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
                   s2.setAdapter(cadapter);

                // When user selects a university
                    s2.setOnItemSelectedListener(new OnItemSelectedListener() {

                                @Override
                                public void onItemSelected(AdapterView<?> arg0, 
View arg1,
                                                int arg2, long arg3) {

                                                 //Get the selected building
                                           String selectedItemString = (String) 
s2.getSelectedItem();
                                           System.out.println
("Building: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+selectedItemString);



                                }

                                @Override
                                public void onNothingSelected(AdapterView<?> 
arg0) {
                                        // TODO Auto-generated method stub
                                }

               });



            // When user selects a university
            s.setOnItemSelectedListener(new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0, View 
arg1,
                                        int arg2, long arg3) {
                                  //Get the selected university
                                   String selectedItemString = (String) 
s.getSelectedItem();
                                   System.out.println
("Uni: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+selectedItemString);

                          if(selectedItemString .equals(""))
                          {
                                  // In case of an error so it won't crash
                                  nospinner();
                          }

                          else
                          {
                                  // Find the table of the selected University 
dynamically
                                  finder(selectedItemString);
                          }

                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                                // TODO Auto-generated method stub
                        }

       });


where finder() is
protected void finder(String selectedItemString) {

               final Dbadapter db = new Dbadapter(this);  // This creates an
instance of the database in this class
           final Spinner s2 = (Spinner) findViewById(R.id.spinner2);
                   // Access Database
                   db.open();

                   // Fix selected item to match the db
                   selectedItemString = (selectedItemString).toLowerCase();
                   selectedItemString = selectedItemString.replaceAll(" ","");

                //   System.out.println("Uni: !!!!!!!!!!!!

                   // Call a function to return the rows of that university
                   final Cursor cur = db.getAllTitles(selectedItemString);

           // Get Columns
           String[] columns = new String[]{"building"};
                   SimpleCursorAdapter cadapter = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item, cur,
                       columns, new int[] {android.R.id.text1});

                   // Spinner Layout and population
                   cadapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
                   s2.setAdapter(cadapter);
                   db.close();

}

whenever the user changes the selection of the first spinner it's
fine, whenever the changes are related to the 2nd spinner I get a
handler exception on this line:   String selectedItemString = (String)
s2.getSelectedItem();

I could get an object on selected item but not the actual String
value.

anyone could help?

thanks a lot
--~--~---------~--~----~------------~-------~--~----~

2. Handler Exception when trying to get Spinner selected Item

Hello,

I am trying to get the selected item of my spinner that is populated
and I am already seeing the values. when I try to use
(String) s.getSelectedItem(); to get the selected item, I am receiving
a handler exception on Logcat.

The spinner throwing the error is a 2nd spinner resulting from the 1st
spinner's selected item (that works perfectly). In other words, user
selects from spinner one and upon selection, populates spinner 2
(until here everything is fine). When trying to get the value of the
selected row in spinner2 , I am receiving the error.

here's the main parts of my code:

    @Override
        public void onCreate(Bundle icicle) {

        super.onCreate(icicle);
        setContentView(R.layout.main);


        // The drop down list for the list of universities
        final Spinner s = (Spinner) findViewById(R.id.spinner);
            ArrayAdapter adapter = ArrayAdapter.createFromResource(
                    this, R.array.universities,
android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
            s.setAdapter(adapter);

            // Initialization of the 2nd spinner
            String[] array = {"this", "is", "driving", "me", "crazy"};
                final Spinner s2 = (Spinner) findViewById(R.id.spinner2);
                ArrayAdapter<String> cadapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, array);
                cadapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
                s2.setAdapter(cadapter);
 // When user selects a university
            s.setOnItemSelectedListener(new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0, View 
arg1,
                                        int arg2, long arg3) {
                                  //Get the selected university
                                   String selectedItemString = (String) 
s.getSelectedItem();
                                 //  System.out.println
("Uni: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+selectedItemString);

                          if(selectedItemString .equals(""))
                          {
                                  // In case of an error so it won't crash
                                  nospinner();
                          }

                          else
                          {
                                  // Find the table of the selected University 
dynamically
                                 finder(selectedItemString);
                          }

                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                                // TODO Auto-generated method stub
                        }




       });

         // When user selects a university
                s2.setOnItemSelectedListener(new OnItemSelectedListener() {

                                @Override
                                public void onItemSelected(AdapterView<?> arg0, 
View arg1,
                                                int arg2, long arg3) {

                        //                      String selected  = 
(String)s2.getSelectedItem();  <---- it
crashes here
                                //              System.out.println
("Building: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+selected);
                                }

                                @Override
                                public void onNothingSelected(AdapterView<?> 
arg0) {
                                        // TODO Auto-generated method stub
                                }
               });

     }

protected void finder(String selectedItemString) {


               final Dbadapter db = new Dbadapter(this);  // This creates an
instance of the database in this class
           final Spinner s2 = (Spinner)findViewById(R.id.spinner2);
                   // Access Database
                   db.open();

                   // Fix selected item to match the db
                   selectedItemString = (selectedItemString).toLowerCase();
                   selectedItemString = selectedItemString.replaceAll(" ","");


                   // Call a function to return the rows of that university
                   final Cursor cur = db.getAllTitles(selectedItemString);
                //cur.moveToFirst();

           // Get Columns
           String[] columns = new String[]{"building"};
                   SimpleCursorAdapter cadapter = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item, cur,
                                   columns, new int[] {android.R.id.text1});

                   // Spinner Layout and population
                   cadapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
                   s2.setAdapter(cadapter);
                   db.close();
                }

--~--~---------~--~----~------------~-------~--~----~

3. Android on Galileo

4. Alarm Manager

5. Is there a way to access the serial device on G1

6. Progress Dialog When Application Starts

7. Wrapping onCreateInputConnection for 1.1 safety