0

i have a share button inside eache item of an @listview Application starts well, but it crashes when I press Facebook sharebutton button.

holder.button = (ShareButton) v.findViewById(R.id.btnOne);
holder.button.setOnClickListener(new View.OnClickListener() { 

@Override 
public void onClick( View v) {

    v.setTag(holder);

    Drawable mDrawable =  holder.imageview.getDrawable();
    Bitmap image = ((BitmapDrawable)mDrawable).getBitmap();

    SharePhoto photo = new SharePhoto.Builder().setBitmap(image)
   .build();

    SharePhotoContent content = new SharePhotoContent
          .Builder().addPhoto(photo).build();

    ShareApi.share(content, null);                                  
}       

});

and thhis is the logCat logCat

Manifest

   <meta-data android:name="com.facebook.sdk.ApplicationName"android:value="@string/app_name" />

<provider android:authorities="com.facebook.app.FacebookContentProvider(app id )"
      android:name="com.facebook.FacebookContentProvider"
      android:exported="true" /> 


    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
hinata
  • 23
  • 6

1 Answers1

0

Use this code snippet for sharing content to facebook:

private Context mContext;    

public void setupFacebookShareIntent() {

            ShareDialog shareDialog;

            FacebookSdk.sdkInitialize(mContext);
            shareDialog = new ShareDialog((Activity) mContext);

            ShareLinkContent linkContent = new ShareLinkContent.Builder()
                    .setContentTitle("YOUR TITLE")
                    .setContentDescription("YOUR DESCRIPTION")
                    .setContentUrl(Uri.parse("http://xxxx.com/"))
                    .setImageUrl(Uri.parse("http://xxxx.com/"))
                    .build();

            shareDialog.show(linkContent);
        }
Sin
  • 83
  • 9
  • thanks for the quick reply i went just to ask you can i add this function in "MediaAdapter.java" for example ??!! becouse i have a problem whit this ====== """" shareDialog = new ShareDialog(this); """"" – hinata May 03 '16 at 19:30
  • ============= The constructor ShareDialog(MediaAdapter) is undefined – hinata May 03 '16 at 19:33
  • i think that i have a problem in facebook sdk (4.0) so now I decided to share image using "intent " ===================== http://stackoverflow.com/questions/37059906/incorrect-data-retrieved-from-item-in-listview-share-button-android – hinata May 05 '16 at 20:45