Question

After researching SO and Google, I think that due to my limited english, I cannot find an answer to my question.

In an Activity, I simply want to open the "message option dialog" when clicking a button. It should recognize wheter the user has WhatsApp or not and put that option in the dialog (or not). Optionally for all possible message applications like facebook, hangouts. Is there a global way to achieve this?

I am sorry to not provide some code, but I think this is more a general question.

Était-ce utile?

La solution

Android has this thing called Intents.

It basically means that applications can register to handle certain intents, and your application can ask Android to provide a list of applications that can do what you are asking.

To send a message, you need to create a intent that looks like:

//create our intent with a action of ACTION_SEND
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//we want to send a simple 'text' message
sendIntent.setType("text/plain");
//this is the text we are sending
sendIntent.putExtra(Intent.EXTRA_TEXT, messageToSend);
//ask android to show apps that can handle this intent
startActivity(Intent.createChooser(sendIntent, "Send message"));

Hope that helps!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top