我可以使用他们的sharDialog()弹出窗口发布到Facebook。但是,如果我想在点击按钮上发布设置消息,而不弹出对话框,我该怎么做呢?
public class MainActivity extends AppCompatActivity {
private ShareDialog share;
private ShareLinkContent content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
content = new ShareLinkContent.Builder().setContentTitle("CURRENT LOCATION").build();
share = new ShareDialog(this);
ImageButton fbBut = (ImageButton) findViewById(R.id.facebook_button);
fbBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
share.show(content);
}
});
}
@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) {
//Opens the settings preferences
Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
MainActivity.this.startActivity(settings);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
// Logs 'install' and 'app activate' App Events.
AppEventsLogger.activateApp(this);
}
@Override
protected void onPause() {
super.onPause();
// Logs 'app deactivate' App Event.
AppEventsLogger.deactivateApp(this);
}
}
这是我到目前为止的代码。