All I can think of is to step away. If for example you are at home with a friend visiting, and they start texting and doing email, step out of the room and start doing some project, dust your living room, or go into the kitchen. They will realize you are gone (hopefully) and ask "where did you go?" That is the perfect opportunity to say, "I thought we were visiting but you seemed otherwise engaged so I thought our visit was over."
In other settings, I guess you would just have to be honest and say, "do you think that you could turn off your phone so that we can have a conversation?"
All of this is not my first instinct--my first thought was to grab the phone and throw it out the window which, of course, we all know would be wrong - but so satisfying.