Sharing Highscore with Social Media

Sharing highscore screenshot in social media Android

You could use a Share intent to share your image. This will cause Android to show a dialog with all available apps that can share and image. The dialog will contain Facebook, twitter, google plus, SMS, whatsapp etc. if they are installed.

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");// image/png if it's a png

share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("<path_to_image>"));

startActivity(Intent.createChooser(share, "Share Highscore"));

You will need to save your screenshot somewhere on the external or internal storage and provide the intent with a path to it before this can be done.

Reward user after successful sharing on social media on Android?

  1. For Twitter you can user Twitter Kit Native Composer to share a tweet which is basically an activity that you start with

    startActivity(intent);

    Later a broadcast will be fired by twitter with the result of the sharing, showing wether it was successful or not. More info here: https://dev.twitter.com/twitterkit/android/compose-tweets

  2. For Facebook you can get share status too, when you show sharing dialog you are able to provide a callback that will notify you about the success of sharing.

    public class MainActivity extends FragmentActivity {
    CallbackManager callbackManager;
    ShareDialog shareDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    callbackManager = CallbackManager.Factory.create();
    shareDialog = new ShareDialog(this);
    shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
    // Here you'll get sharing status
    });
    }

    More info: https://developers.facebook.com/docs/sharing/android?locale=en_US, check the Share Dialog paragraph.

  3. For LinkedIn you can get a result from their sdk similar to handling a network request.

  4. For Google+ you should check the result of started activity, regarding to this docs developers.google.com/+/mobile/android/share you should call startActivityForResult and then you most likely will get the result as activity result, Activity.RESULT_OK or Activity_RESULT_CANCELED. More info here: https://developer.android.com/training/basics/intents/result.html

  5. For Reddit you can use their REST api. I've found that you can compose a post for example: https://reddit.com/dev/api/#POST_api_compose that will response with success or failure.

  6. Fow WhatsApp, Hangouts, Telegram, Viber, Line and other messengers you are supposed to use native android way to share that unfortunately does not tell you the result.

How to handle Multiple Social Media Logins and sessions Flow on Android?

I have done it several times and the best approach I can recommend you is:

  • Extract what part of the integration you want to add. It is only sharing, do you want to let the user start a session, do you need any kind of API keys.
  • Once done the first step, you can extract some abstraction layer methods that are common to all the social platforms (there is always almost always a common function).
  • Generate a factory for every platform like FacebookFactory or TwitterFactory that are capable to generate prepared objects for a given task. Imagine you want to login, then ask to the concrete factory for the LoginTask and expose common actions like requestOAuthToken, getSession, etc. If for another reason there is something that cannot be abstracted, you can always downcast knowing that it will not break your application.
  • You can generate to feel more confortable a second abstraction layer by using a Facade pattern, which is constructed via Context object (some networks like facebook are really invasive and need to know many things), deciding which is the social network you want to work on by an enum.

Here it is a mock example on how your code can look like:

SocialFacade facade = SocialFacade.getInstance();
SocialSession session = facade.getSession(Network.Twitter);
String token = session.requestToken(apiId);
facade.getShare(Network.Twitter).sharePost(apiId, message);

Of cours you can use some kind of third party library, but this is the approach I use when nothing suits my needs.

How to fix this social media view sharing (iOS)?

Late answer, but here is the code that I'm using for something similar:

 //takes screenshot
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Share image and text

NSString *text = [NSString stringWithFormat:@"My score"];

UIActivityViewController *controller =
[[UIActivityViewController alloc]
initWithActivityItems:@[text, capturedScreen]
applicationActivities:nil];

controller.excludedActivityTypes = @[
UIActivityTypeAssignToContact,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
];

[self presentViewController:controller animated:YES completion:nil];

I hope that help.

How to handle Multiple Social Media Logins and sessions Flow on Android?

I have done it several times and the best approach I can recommend you is:

  • Extract what part of the integration you want to add. It is only sharing, do you want to let the user start a session, do you need any kind of API keys.
  • Once done the first step, you can extract some abstraction layer methods that are common to all the social platforms (there is always almost always a common function).
  • Generate a factory for every platform like FacebookFactory or TwitterFactory that are capable to generate prepared objects for a given task. Imagine you want to login, then ask to the concrete factory for the LoginTask and expose common actions like requestOAuthToken, getSession, etc. If for another reason there is something that cannot be abstracted, you can always downcast knowing that it will not break your application.
  • You can generate to feel more confortable a second abstraction layer by using a Facade pattern, which is constructed via Context object (some networks like facebook are really invasive and need to know many things), deciding which is the social network you want to work on by an enum.

Here it is a mock example on how your code can look like:

SocialFacade facade = SocialFacade.getInstance();
SocialSession session = facade.getSession(Network.Twitter);
String token = session.requestToken(apiId);
facade.getShare(Network.Twitter).sharePost(apiId, message);

Of cours you can use some kind of third party library, but this is the approach I use when nothing suits my needs.



Related Topics



Leave a reply



Submit