Share image and text to the facebook in android.PLease follow the below source code
String fbMsg="hi facebook";
byte[] image=getImageData();//Get the byte array of image data
Bundle b=new Bundle();
b.putByteArray("picture", image);
b.putString("message", fbMsg);
String facebookMessage = getIntent().getStringExtra("facebookPrayer");
if (facebookMessage == null)
{
//Post text and image through bundle parameter "b"
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/photos", b, "POST", new SampleUploadListener(), null);
}
public static byte[] getImageData()
{
Bitmap bitmap=BitmapFactory.decodeResource(ctx.getResources(),R.drawable.ic_launcher);
ByteArrayOutputStream bao=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte[] bitMapData = bao.toByteArray();
return bitMapData;
}
SampleUploadListener.class
public class SampleUploadListener implements AsyncFacebookRunner.RequestListener {
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
String fbMsg="hi facebook";
byte[] image=getImageData();//Get the byte array of image data
Bundle b=new Bundle();
b.putByteArray("picture", image);
b.putString("message", fbMsg);
String facebookMessage = getIntent().getStringExtra("facebookPrayer");
if (facebookMessage == null)
{
//Post text and image through bundle parameter "b"
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/photos", b, "POST", new SampleUploadListener(), null);
}
public static byte[] getImageData()
{
Bitmap bitmap=BitmapFactory.decodeResource(ctx.getResources(),R.drawable.ic_launcher);
ByteArrayOutputStream bao=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte[] bitMapData = bao.toByteArray();
return bitMapData;
}
SampleUploadListener.class
public class SampleUploadListener implements AsyncFacebookRunner.RequestListener {
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
No comments:
Post a Comment