-2

I am developing an application which have an option to share an image via facebook. I use the following code for posting and i am using sdk 3.0. I cant change the sdk version due to some reasons. Please help me.

    public void postImage() 
    {

    Bitmap img = BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_launcher);

    Request uploadRequest = Request.newUploadPhotoRequest(
                    Session.getActiveSession(), img, new Request.Callback() {

                        @Override
                        public void onCompleted(Response response) {
                            Toast.makeText(PhotoGallery.this,
                                    "Photo uploaded successfully",
                                    Toast.LENGTH_LONG).show();
                        }
                    });
}

Also i use

<provider
            android:name="com.facebook.NativeAppCallContentProvider"
            android:authorities="com.facebook.app.NativeAppCallContentProvider1613067868978775"
            android:exported="true" />

in manifest

Edit

OK, finaly i got the problem, in ported android applications, facebook sdk does not support photo sharing. But, we can share simple messages on the wall using fb sdk.

userDroid
  • 198
  • 9

1 Answers1

1

This is what I used to do :

    private void initShareIntent() {
    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("face") ||
                    info.activityInfo.name.toLowerCase().contains"face")) {
                share.putExtra(Intent.EXTRA_TEXT, "Elevator Express");
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); // Optional, just if you wanna share an image.
                share.setPackage(info.activityInfo.packageName);
                found = true;
                break;
            }
        }
        if (!found) {
                Toast.makeText(getApplicationContext(), "Facebook does not exist", Toast.LENGTH_SHORT).show()
            return;
        }
        startActivity(Intent.createChooser(share, "Select"));
    }
}
Miriana Itani
  • 865
  • 9
  • 25