So I'm builing an Android social game.
What's the best strategy to get the user invite his friends in the game ? How to mix facebook connect, SMS, emails from the contact list ? What application does this perfectly in the minimum amoun开发者_StackOverflow中文版t of steps.
Try using the ACTION_SEND intent, like this:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try (your game) for Android!");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I'm using (your game) for Android and I recommend it. Click here: http://www.yourdomain.com");
Intent chooserIntent = Intent.createChooser(shareIntent, "Share with");
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(chooserIntent);
This code will present a menu with all the applications that can send messages, including Facebook, Twitter, SMS, email, ...etc. The only limitation is that you can only share links with Facebook, so EXTRA_SUBJECT must be a pure URL or the user will get an error if they choose Facebook. In other words only this will work with Facebook:
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "http://www.yourdomain.com");
If you want to share other text (like in the example above) you must create a separate share function for Facebook.
Barry
精彩评论