I am working with the Facebook Sharing Product for Android. Link and photo sharing are functioning.. Now my goal is to take a FrameLayout from the Application with all its Widgets, convert it to a Bitmap and then Share it on Facebook.
I have found the following question and answers on Stack, and went to work with them. Convert frame layout into image and save it
Following is my code:
public class LoginActivity extends AppCompatActivity {
//callbackmanager manages callbacks to facebook sdk
private CallbackManager callbackManager;
private ShareButton framelayout_button;
private FrameLayout frameLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
//STILL NEED TO INCLUDE THE PERMISSIONS SOMEWHERE..
frameLayout = (FrameLayout) findViewById(R.id.framelayout_facebook);
Bitmap bitmap = Bitmap.createBitmap(frameLayout.getWidth(), frameLayout.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
frameLayout.draw(canvas);
SharePhoto frame_photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.build();
SharePhotoContent framelayout_content = new SharePhotoContent.Builder()
.addPhoto(frame_photo)
.build();
framelayout_button = (ShareButton) findViewById(R.id.Sharebutton_FrameLayout);
framelayout_button.setShareContent(framelayout_content);
}
}
I get the following error in my LogCat:
java.lang.IllegalArgumentException: width and height must be > 0
My width and height defined in Layout file are both > 0, so something else must be wrong.
Any ideas?