My immediate suggestion is to ban electronic devices at the table, except those needed for the game (e.g. a tablet with a character sheet on it).
Be blunt with the players.
"I'm here, giving you my 100% attention for two or three hours. I've also spent twice as many hours beforehand preparing for this. Its just common courtesy that you give me your 100% attention."
If a player says they need the tablet for their character sheet, then that's OK, on the understanding that if I see Facebook or Angry Birds or anything that is not a character sheet or a rulebook then I'm taking the tablet away from them and they play the rest of the session from memory. Oh, and if they misremember anything about their character's statistics, they get a large penalty.
If they don't have the option of playing games or using social networking then they will be more likely to fill their time with gaming stuff.
To repeat - this is just common courtesy.
To stress - paying attention to the other people at the table (and not playing Diplomacy) is the minimum standard I expect from people, whether it is a card game or a board game or a roleplaying game. The comment about playing their character from memory is a lighthearted way of saying "pay attention to the game or leave the table."
To quote AngryGM: In point of fact, there’s really only one useful piece of advice GMs ever give players. One. And that is this: “pay attention to the —ing game, even when you are not directly involved, because you never know when you will have to be involved and you make us repeat things and stop the game for you when you don’t.”
Vary the timing of scenes. Follow luxuriously slow scenes with fast! frenetic! chaotic! action! What does your character do? Nothing? Too Slow! Next person? Go. Go. Go.
When a player looks up from their smartphone and goes "huh, what just happened?", do not stop and explain. Just move on. Leave them confused and disadvantaged. It's their fault they missed out on exciting stuff. Next time, they will pick up on the cues in your voice and pay attention, because they don't want to miss out the cool things.
If a character is present, then ask the appropriate player for input.
For example, the party is in the cell talking to a noble about getting freed. The noble asks the Paladin "So, what's your take on this?" If the player doesn't immediately answer, then just move on, but make a note that the character snubbed the NPC (see Consequences below).
Add tension by making a ticking clock, something that the players and the characters can see. The more tense a scene, the more likely they will want to participate.
They are in jail but they need to warn someone about an incoming disaster. Perhaps a dam is going to break? Perhaps an army of giants is heading to town, fleeing the bad weather? perhaps they know when the big earthquake will strike?
Every minute they spend in the cell is a minute the mayor is not organising defences.
So, put an alarm clock on the table. An old style one with a loud ticking. When the alarm goes off, the earthquake hits.
Something physical in the middle of the table will generally get everyone's attention. I like putting together notes and handouts and maps and the like, so its easy for me.
As a bonus, having a letter in the middle of the table that the players have to read saves your voice.
Make sure their actions have consequences and make sure those consequences are visible to the players.
A week later, in a store (maybe an armour and weapons shop), the proprietor recognises the Paladin. "Oh, hey, I know you, you're pillow-fort guy! What are you doing in here? Shouldn't you be down the road at the sewing shop?"
The barbarian is trying to get services from a noble. "Oh, now you want to engage with me? Well, too late, you lost your chance two weeks ago in that jail cell."
GM to players:
"You have a rulebook. All common items are for sale, at 10% extra price. You have five minutes. Go."
To address the question in the comments. "How do you propose that stealing peoples' stuff and penalising them for not memorising their sheet for a game they don't seem interested in will make them more interested in sticking around for it? Has this ever worked out for you in comparable circumstances?" Yes, it has. It made the people who weren't willing to commit to the game go away so the rest of us could play the game without distractions. I've been in that situation twice. First time, I called off the entire campaign, which in hindsight was not the best idea because it meant none of us had any fun. Second time, I put the hard question at the table. Two players left, the rest of us went on to have a good game.
"A DM who treats their players like that might find many of them quitting the game." Good. If a player is not willing to show respect to the other people at the table by paying attention then they aren't welcome at the table.
Personally, I prefer the word "consequences" over "punishments". The consequence of a player's bad manners is that they don't play the game.