0

I'm creating an Android game and I want that the user can share the game's screenshot when the game finishs. Exactly like this (game 2048):

enter image description here

I want that the user can write the message and click by himself the publish button.

I know how to take a screenshot and I tried the Facebook API:

            Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), img,  uploadPhotoRequestCallback);
        Bundle parameters = request.getParameters();
        parameters.putString("message", "My message");
        request.setParameters(parameters);
        request.executeAsync();

But this code upload directly the photo, while I want only to (i) open facebook post window; (ii) select automatically the image. Then, the user can do the rest.

How can I do that?

Thanks.

user1289984
  • 90
  • 1
  • 9

1 Answers1

0

Ok, I resolved this issue using Intent. This is the right way to do what I wanted. In this way I can share directly on facebook (avoiding show the choosing window).

private void initShareIntent(String type) {
    boolean found = false;
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("image/jpeg");

    // gets the list of intents that can be loaded.
    List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
    if (!resInfo.isEmpty()){
        for (ResolveInfo info : resInfo) {
            if (info.activityInfo.packageName.toLowerCase().contains(type) || 
                    info.activityInfo.name.toLowerCase().contains(type) ) {
                if(info.activityInfo.name.toLowerCase().contains("messenger")){
                    continue;
                }
                Log.i("tag", "_info_name_"+info.activityInfo.name);
                share.putExtra(Intent.EXTRA_SUBJECT,  "subject");
                share.putExtra(Intent.EXTRA_TEXT,     "your text");
                Bitmap img= Blur.takeScreenShot(PlayActivity.this);
                String pathofBmp = Images.Media.insertImage(getContentResolver(), img,"title", null);
                Uri bmpUri = Uri.parse(pathofBmp);
                share.putExtra(Intent.EXTRA_STREAM, bmpUri); // Optional, just if you wanna share an image.
                share.setPackage(info.activityInfo.packageName);
                found = true;
                break;
            }
        }
        if (!found)
            return;

        startActivity(Intent.createChooser(share, "Select"));
    }
}

I modified the example proposed here. The problem with the previously proposed code is that if Facebook Messenger is installed on the device, this code select Facebook Messenger and not Facebook. In addition there is the code to retrieve the image uri from Bitmap.

The use is: initShareIntent("facebook") or initShareIntent("twitter") etc...

Community
  • 1
  • 1
user1289984
  • 90
  • 1
  • 9