Android上的FaceBook共享
我无法在facebook上共享我的屏幕。下面是我的代码。 你能帮我拍下我的活动的截图并在facebook的墙上发布吗Android上的FaceBook共享,android,Android,我无法在facebook上共享我的屏幕。下面是我的代码。 你能帮我拍下我的活动的截图并在facebook的墙上发布吗 public class MainActivity extends Activity { // share button private ShareButton shareButton; // image private Bitmap image; // counter private int counter = 0; /
public class MainActivity extends Activity {
// share button
private ShareButton shareButton;
// image
private Bitmap image;
// counter
private int counter = 0;
//private ShareContent shareContent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// initialize facebook sdk
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
// share button
shareButton = (ShareButton) findViewById(R.id.share_btn);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
postPicture();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void postPicture() {
// check counter
if (counter == 1) {
// save the screenshot
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
// creates immutable clone of image
image = Bitmap.createBitmap(rootView.getDrawingCache());
// destroy
rootView.destroyDrawingCache();
// share dialog
AlertDialog.Builder shareDialog = new AlertDialog.Builder(this);
shareDialog.setTitle("Share Screen Shot");
shareDialog.setMessage("Share image to Facebook?");
shareDialog.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// share the image to Facebook
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image).build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo).build();
shareButton.setShareContent(content);
counter = 1;
shareButton.performClick();
}
});
shareDialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
shareDialog.show();
} else {
counter = 0;
shareButton.setShareContent(null);
}
}
}
有错误吗?如果您的设备中安装了AnyDoe facebook本机应用程序,请发布stacktrace是的,但当我按下fshare按钮时,没有显示错误,它只是显示消息“将图像共享到facebook?”我按了“是”,但什么也没发生。我的主要目的是当我按下应用程序上的“共享”按钮时,整个屏幕都会像这样贴在FaceBook的墙上。有错误吗?如果您的设备中安装了AnyDoe facebook本机应用程序,请发布stacktrace是的,但当我按下fshare按钮时,没有显示错误,它只是显示消息“将图像共享到facebook?”我按了“是”,但什么也没发生。我的主要目的是当我按下应用程序上的“共享”按钮时,整个屏幕都会像这样贴在FaceBook的墙上