Friday, November 6, 2009

Re: [android-developers] Re: Working with the new ContactContracts API

Here's what you might want to know about deletion:

- Deleting an aggregated contact will delete all constituent raw contacts
- Deleting all constituent raw contacts will delete the aggregated contact
- Deleting a raw contact automatically deletes all constituent data rows.
- This is a technical detail, but resolver.delete(...), does not physically delete a raw contacts row.  It sets the DELETED flag on the raw contact.  The sync adapter then deletes the raw contact from the server and finalizes phone-side deletion by calling resolver.delete(...) again and passing the CALLER_IS_SYNCADAPTER query parameter.

Cheers,
- Dmitri

On Fri, Nov 6, 2009 at 2:09 AM, jarkman <jarkman@gmail.com> wrote:
Jake - thanks for that. Your code seems to match my understanding of
Dmitri's recipe, and also actually seems to work for me. Which i hope
is good news... :-)

Richard

On Nov 5, 9:20 pm, "jak." <koda...@gmail.com> wrote:
> Hi Dmitri & Jarkman,
> Hope everyone's having a good day.
>
> I'm also working on adding photo's for a contact. Based on your
> discussion I came up with this method.
> It's seems to do the job, but I'm not entirely confident that I'm
> doing things in the best way.
> Can you please review it and let me know If I am fully grasping the
> concept. I'm a little confused about when to use CONTACT_ID vs.
> RAW_CONTACT_ID etc.
>
> Code below. Thanks a bunch!
> Jake
>
> -------
>
> public static void setPhoto(Uri personUri, byte[] photo, Context
> context) {
>     ContentValues values = new ContentValues();
>     int photoRow = -1;
>     String where = ContactsContract.Data.RAW_CONTACT_ID + " == " +
> ContentUris.parseId(personUri) + " AND " + Data.MIMETYPE + "=='" +
> ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
>     Cursor cursor = context.getContentResolver().query
> (ContactsContract.Data.CONTENT_URI, null, where, null, null);
>     int idIdx = cursor.getColumnIndexOrThrow
> (ContactsContract.Data._ID);
>     if(cursor.moveToFirst()){
>         photoRow = cursor.getInt(idIdx);
>     }
>     cursor.close();
>
>     values.put(ContactsContract.Data.RAW_CONTACT_ID,
> ContentUris.parseId(personUri));
>     values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
>     values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, photo);
>     values.put(ContactsContract.Data.MIMETYPE,
> ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
>
>     if(photoRow >= 0){
>         context.getContentResolver().update
> (ContactsContract.Data.CONTENT_URI, values, ContactsContract.Data._ID
> + " = " + photoRow, null);
>     } else {
>         context.getContentResolver().insert
> (ContactsContract.Data.CONTENT_URI, values);
>     }
>
> }
>
> On Nov 5, 12:17 pm, Dmitri Plotnikov <dplotni...@google.com> wrote:
>
> > Right.
>
> > Setting the new photo to super-primary should take care of the PHOTO_ID
> > reference.  You should not need to worry about resetting the super-primary
> > flag on other photos for the same contact - that's also automatic.
>
> > Cheers,
> > - Dmitri
>
> > On Thu, Nov 5, 2009 at 12:04 PM, jarkman <jark...@gmail.com> wrote:
> > > Oops! I see what you mean. Perhaps that update was a little
> > > bold... :-)
>
> > > So I need to search out the right row (with the right contact ID and
> > > the photo's MIME type) in the Data table with a query, then update
> > > that row ?
>
> > > If there isn't a pre-existing photo, do I also need to update
> > > ContactsContract.Data.PHOTO_ID on the contact after I have added a
> > > photo ?
>
> > > Thanks!
>
> > > R.
>
> > > On Nov 5, 7:09 pm, Dmitri Plotnikov <dplotni...@google.com> wrote:
> > > > This line:
>
> > > > context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
> > > > values, ContactsContract.Data.RAW_CONTACT_ID + " = " + personId,
> > > > null);
>
> > > > attempts to change ALL data rows that have RAW_CONTACT_ID == personId,
> > > which
> > > > includes the photo, but also phone numbers, emails etc.  You will need to
> > > > find the specific row before updating it. The condition should say:
> > > Data._ID
> > > > + "=" + dataId.  Alternatively, you can construct a specific URI:
> > > > ContentUris.withAppendedId(Data.CONTENT_URI, dataId)
>
> > > > I hope this helps.
> > > > - Dmitri
>
> > > > On Thu, Nov 5, 2009 at 9:05 AM, jarkman <jark...@gmail.com> wrote:
> > > > > Dmitri - I wasn't, but I am now - thanks for the tip.
>
> > > > > It doesn't fix the problem, though. It seems as though I can set the
> > > > > photo once on a brand-new contact, but I can never set it again on
> > > > > that contact.
>
> > > > > Do I perhaps need to do something with
> > > > > ContactsContract.Data.PHOTO_ID ?
>
> > > > > Here's code:
>
> > > > > ContentValues values = new ContentValues();
> > > > > values.put(ContactsContract.Data.RAW_CONTACT_ID, personId);
> > > > > values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
> > > > > values.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
> > > > > bytes.toByteArray());
> > > > > values.put(ContactsContract.Data.MIMETYPE,
> > > > > ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE );
>
> > > > > context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
> > > > > values, ContactsContract.Data.RAW_CONTACT_ID + " = " + personId,
> > > > > null);
>
> > > > > And here's a stack:
>
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103): Writing exception to
> > > > > parcel
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):
> > > > > android.database.sqlite.SQLiteException: unknown error: Unable to
> > > > > convert BLOB to string
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > android.database.CursorWindow.getString_native(Native Method)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > android.database.CursorWindow.getString(CursorWindow.java:329)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > android.database.AbstractWindowedCursor.getString
> > > > > (AbstractWindowedCursor.java:49)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
>
> > > com.android.providers.contacts.ContactsProvider2$DataRowHandler.getAugmente dValues
> > > > > (ContactsProvider2.java:1038)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
>
> > > com.android.providers.contacts.ContactsProvider2$CommonDataRowHandler.updat e
> > > > > (ContactsProvider2.java:1225)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
>
> > > com.android.providers.contacts.ContactsProvider2$PhoneDataRowHandler.update
> > > > > (ContactsProvider2.java:1445)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > com.android.providers.contacts.ContactsProvider2.updateData
> > > > > (ContactsProvider2.java:3091)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > com.android.providers.contacts.ContactsProvider2.updateData
> > > > > (ContactsProvider2.java:3075)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > com.android.providers.contacts.ContactsProvider2.updateInTransaction
> > > > > (ContactsProvider2.java:2854)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > com.android.providers.contacts.SQLiteContentProvider.update
> > > > > (SQLiteContentProvider.java:139)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > com.android.providers.contacts.ContactsProvider2.update
> > > > > (ContactsProvider2.java:1923)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > android.content.ContentProvider$Transport.update(ContentProvider.java:
> > > > > 180)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > android.content.ContentProviderNative.onTransact
> > > > > (ContentProviderNative.java:195)
> > > > > 11-05 17:03:36.781: ERROR/DatabaseUtils(103):     at
> > > > > android.os.Binder.execTransact(Binder.java:287)
>
> > > > > On Nov 5, 4:41 pm, Dmitri Plotnikov <dplotni...@google.com> wrote:
> > > > > > Hi Richard,
>
> > > > > > Regarding photos: are you setting the IS_SUPER_PRIMARY flag on your
> > > Photo
> > > > > > row?  The notion of "super-primary" has to do with multiple accounts.
> > > > >  You
> > > > > > can have only one super-primary photo for an entire aggregated
> > > contact.
>
> > > > > > Cheers,
> > > > > > - Dmitri
>
> > > > > > On Thu, Nov 5, 2009 at 1:51 AM, jarkman <jark...@gmail.com> wrote:
> > > > > > > Jake - no, you are not the only one who suffers that frustration
> > > with
> > > > > > > the ContactsContract documentation.
>
> > > > > > > I've spent a lot of time writing frankly experimental code because
> > > I
> > > > > > > couldn't work out from the docs how the various URIs and string
> > > > > > > constants had to be knitted together to actually work. I think the
> > > > > > > docs really need a lot more tiny examples, to make the context
> > > clear
> > > > > > > for each definition.
>
> > > > > > > I still can't work out how to set contact photos reliably. I
> > > thought I
> > > > > > > had a fix yesterday, but it fails in some cases. Tiem for more
> > > > > > > experiments...
>
> > > > > > > Richard
>
> > > > > > > On Nov 5, 2:11 am, "jak." <koda...@gmail.com> wrote:
> > > > > > > > Thank you Dmitri,
>
> > > > > > > > Your response was very helpful. Along with that, and the sample
> > > you
> > > > > > > > posted on another thread about using both Contact Apis from one
> > > app,
> > > > > > > > I've gotten most of the way there. It is much appreciated.
>
> > > > > > > > I'm still however having some problems that I'm hard pressed to
> > > find
> > > > > a
> > > > > > > > solution for.
> > > > > > > > I'd be grateful if anyone could help me.
>
> > > > > > > > The biggest challenge I'm  having with this API is that it's hard
> > > for
> > > > > > > > me to picture how the tables are laid out so I know which URI to
> > > > > query
> > > > > > > > to get the parts of the contact that I'm interested in.
> > > > > > > > I found to get the email address for a contact I'm looking at I
> > > can
> > > > > > > > query the uri:ContactsContract.CommonDataKinds.Email.CONTENT_URI,
> > > > > > > > looking at rows of the contact id i'm interested in.
>
> > > > > > > > However to get the note from the same contact I can't use a
> > > similar
> > > > > > > > pattern, because there is no
> > > > > > > > ContactsContract.CommonDataKinds.Note.CONTENT_URI
> > > > > > > > The Note type exists in CommonDataKinds but it doesn't have an
> > > > > > > > associated CONTENT_URI.
>
> > > > > > > > I'm finding it very frustrating to use this API because every
> > > time I
> > > > > > > > go to try to pull out another piece of data from the contact, the
> > > > > > > > method to access it seems to change (as I can't find a consistent
> > > way
> > > > > > > > to get a given field from a contact). And the documentation never
> > > > > > > > describes how these keys, tables, and URIs are related. Basically
> > > the
> > > > > > > > ContactsContract documentation just gives you a giant list of
>
> ...
>
> read more »

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Audio Capture with Signal level indicator.

Hi

I want to capture audio and along with the audio I also want to show
the live signal strength of the audio on the screen.

Is there ant api that give me information regarding the the loudness
level (or at least some information indicating whether the user is
silent or speaking something) of the audio or should I implement my
own signal processing using the captured buffers and determine the
level.

Regards
gshetty

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Handling back button with Soft keypad

Hi

I have a simple edit control in my application and as expected the
soft keypad comes up on tapping it.

Now what I want to do is that when the user presses the back button,
the activity should quit immediately without the soft keypad going
down first.
On handling the key event in my activity i found that the first 'Back'
event is consumed by the keyboard and it does not even reach the
activity. However once the soft keypad goes down, the events can be
handled in my activity.

Is there any way to override this behavior so that the back button
first reaches my activity and I can quit immediately.

Regards
gshetty

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How Tab Pages switch when User Flick left/right?

I'm using tabs in one of my activities, and I'm not seeing this
behaviour. I'm coding for (and using) Android 1.5 currently, so maybe
it was added as a feature in 1.6 or 2.0? The other thing that might
play into it is, if you're using a TabActivity as base for your
activity. It may have this feature, and since I'm just using a regular
Activity as base, I suppose this could play into it.

But I don't really know.. I just know that I'm not seeing this
behaviour at all.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How to debug Activity resurrection when process was killed by OS.

Hi,

I have activity "A" that launches phones Image Gallery for the user to
pick a picture. In some cases the OS decides there is not enough
memory and kills my process.

In A's onActivityResult() I start a thread that does some lengthy work
with the picture. This thread depends on A.blah field, that is set in
onCreate() (or should be).

According to this http://developer.android.com/guide/topics/fundamentals.html#actlife
when my process is killed the onCreate() is called and so A.blah
should be initialized and so my threads run() method that is invoked
from onActivityResult() should not get null reference, but it does.

Is there any way for me to debug this? I mean can I somehow force the
phone or emulator into killing my process so I can put the breakpoints
and see what's going on?

I can't reproduce it on my phone but my customers are experiencing the
problem.

Thank you!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: ADC2 Results Post

My app World of Bombs missed the cut
http://zeugame.blogspot.com/
received 3 mails to say i losed.

Good Round 2 to all of selected apps.

Croco


On Nov 5, 11:57 pm, jgostylo <jgost...@gmail.com> wrote:
> Congratulations Dan!  It looks like your app is pretty good.  I did
> not get to review any apps worth while but I assume there were some
> pretty good ones out there.
>
> My app The Great Land Grab ended up in the top 50%.  Interesting to
> see that there was a top 25% rating.  I believe I was also hurt by the
> fact that my app just did not work outside the US (no data to load).
> Nothing in the rules saying that it would not be judged outside the
> US, I just assumed it was a US only competition.  My friend said I did
> that because I am a xenophobe.  Well if I am then I probably deserve
> the loss ;).
>
> On Nov 5, 4:40 pm, Dan Sherman <impact...@gmail.com> wrote:
>
>
>
>
>
> > We just got ours :)
>
> > Congratulations! Your application 'ProjectINF ADC' was selected by Android
> > users as one of the top 20 in the Arcade category! We're excited that you
> > chose to participate in the ADC 2 and wish you luck in the final round as
> > your application is evaluated by users and a panel of judges.
>
> > We've got some screenshots over onhttp://www.chickenbrickstudios.com:)
>
> > - Dan
>
> > On Thu, Nov 5, 2009 at 5:21 PM, Maan Najjar <maan.naj...@gmail.com> wrote:
> > > I didn't get anything too ...
>
> > > On Thu, Nov 5, 2009 at 5:09 PM, f_heft <delphik...@gmail.com> wrote:
>
> > >> I didn't get a mail so far ... :(
> > >> Are these mails beeing send over the next few hours or did I somehow
> > >> miss it?
>
> > >> --
> > >> You received this message because you are subscribed to the Google
> > >> Groups "Android Developers" group.
> > >> To post to this group, send email to android-developers@googlegroups.com
> > >> To unsubscribe from this group, send email to
> > >> android-developers+unsubscribe@googlegroups.com<android-developers%2Bunsubscribe@googlegroups.com>
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/android-developers?hl=en
>
> > >  --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscribe@googlegroups.com<android-developers%2Bunsubscribe@googlegroups.com>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: ADC2 Judging App FC

Yup, is happening to me. For something I'm actually interested in
too :(

On Nov 6, 5:37 pm, dadical <keyes...@gmail.com> wrote:
> Is anyone else seeing problems with the ADC2 judging app throwing a FC
> when trying to install manually?  It's a big miss, since the
> requirement to install manually happens VERY frequently.  Only way out
> is to skip and hope that the next app works.  The FC is actually being
> thrown from com.android.vending
>
> I'm on a G1, non-root, T-Mobile carrier, with 1.6 installed, EDGE,
> with WiFi enabled (and connected).

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en