3

I have a problem to send a picture stored in my SDcard to Facebook.

I have coded two methods for this: The first method is OK. In this case a chooser appears. I chose Facebook on screen, facebook with a complete interface starts. Picture appears in face book. I type a text and press Publish button.

Uri screenshotUri = Uri.parse("file:///sdcard/"+nomFichier);  
try{
Intent intentPartager = new Intent(Intent.ACTION_SEND);
intentPartager.setType("image/*");
intentPartager.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(intentPartager, "Share image using"));               
} 
catch(Exception e){
        e.printStackTrace();
        Toast.makeText(this,R.string.erreurFaceBookAbsent,Toast.LENGTH_SHORT).show();
   }

This method is good to let the user chooses the software to send the picture (MMS, twitter, facebook,...) But I want to simplify the command and call directly facebook. So I use this second method with .setClassName("com.facebook.katana","com.facebook.katana.ShareLinkActivity") instruction to force facebook call. Unfortunately this second doesn't work. Facebook is started but no picture is download in facebook (no appear in facebook). Screen Interface of facebook is also different from first method ???.

Uri screenshotUri = Uri.parse("file:///sdcard/"+nomFichier);  
try{
Intent intentFacebook = new Intent(Intent.ACTION_SEND);
intentFacebook.setType("image/*");
intentFacebook.setClassName("com.facebook.katana","com.facebook.katana.ShareLinkActivity");
intentFacebook.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
//intentFacebook.putExtra(Intent.EXTRA_TEXT, "Mes performances avec SpeedMeter");
intentFacebook.putExtra(Intent.EXTRA_STREAM, screenshotUri);
//startActivity(intentFacebook);
startActivityForResult(intentFacebook, CODE_RETOUR_FACEBOOK);
} catch(Exception e){
        e.printStackTrace();
        Toast.makeText(this,R.string.erreurFaceBookAbsent,Toast.LENGTH_SHORT).show();
        }

Is someone can help me ? Where is the problem with second method ? Cyril

0 Answers0