Android Development: Post Screencap Image to Facebook wall
i have been looking everywhere to find the correct way to post a image + text to facebook using android and facebook sdk. i can get this code to post just a message but when i try to post the screenshot i made it ends up with a null pointer exception. i have tried many different code snippets from other threads but none seem to work for me. the best i can do is this code which will post a message to my wall but not the photo. please tell me what im doing wrong here. much appreciated.
View content = findViewById(R.id.row1);
Log.d("captureScreen", content.getId()+"");
byte[] byteArray=null;
Bitmap screenshot=null;
try {
if (content != null) {
int width = content.getWidth();
int height = content.getHeight();
screenshot = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
content.draw(new Canvas(screenshot));
Log.d("captureScreen", "success");
}
} catch (Exception e) {
Log.d("captureScreen", "Failed");
}
try{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
Log.d("byte array", "sucesss");
} catch(Exception e){
Log.d("byte array", "failed");
}
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response.getGraphObject()
.getInnerJSONObject();
Log.d("onCompleted", "2 sucess");
String postId = null;
try {
postId = graphResponse.getString("id");
Log.d("onCompleted", "3 sucess");
} catch (JSONException e) {
Log.d("json failed", "failed");
Log.i(TAG, "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
} else {
CreateDialog("your post was a sucess", "posted");
}
}
};
Bundle params = new Bundle();
params.putString("message","tester");
//params.putString("method", "photos.upload");
//params.putByteArray("source", byteArray);
// params.putString("caption", "test Caption");
Request request = new Request(session, "me/photos", params,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
i have been looking everywhere to find the correct way to post a image + text to facebook using android and facebook sdk. i can get this code to post just a message but when i try to post the screenshot i made it ends up with a null pointer exception. i have tried many different code snippets from other threads but none seem to work for me. the best i can do is this code which will post a message to my wall but not the photo. please tell me what im doing wrong here. much appreciated.
View content = findViewById(R.id.row1);
Log.d("captureScreen", content.getId()+"");
byte[] byteArray=null;
Bitmap screenshot=null;
try {
if (content != null) {
int width = content.getWidth();
int height = content.getHeight();
screenshot = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
content.draw(new Canvas(screenshot));
Log.d("captureScreen", "success");
}
} catch (Exception e) {
Log.d("captureScreen", "Failed");
}
try{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
Log.d("byte array", "sucesss");
} catch(Exception e){
Log.d("byte array", "failed");
}
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response.getGraphObject()
.getInnerJSONObject();
Log.d("onCompleted", "2 sucess");
String postId = null;
try {
postId = graphResponse.getString("id");
Log.d("onCompleted", "3 sucess");
} catch (JSONException e) {
Log.d("json failed", "failed");
Log.i(TAG, "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
} else {
CreateDialog("your post was a sucess", "posted");
}
}
};
Bundle params = new Bundle();
params.putString("message","tester");
//params.putString("method", "photos.upload");
//params.putByteArray("source", byteArray);
// params.putString("caption", "test Caption");
Request request = new Request(session, "me/photos", params,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
No comments:
Post a Comment