Monday, May 5, 2014

Android - How do I share to facebook app, if installed. Otherwise via web facebook (w
































































































































































































































































So far in Android I know how to wall post to the user's wall via the web but I'd like, the app to detect whether the user has the facebook application installed and if so post via that. Does anyone know how to do this?
































































































































































































































































My code so far is below:
































































































































































































































































































































































































Java Code:








































































































































































































































































public class MainActivity extends Activity
{
private static String FACEBOOK_APP_ID = "276023232498070";
private static final String[] PERMISSIONS = new String[] { "publish_stream","email","user_birthday","user_location" };
private Facebook facebook;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
facebook = new Facebook(FACEBOOK_APP_ID);
Bundle parameters = new Bundle();
parameters.putString("app_id", "276023232498070");
parameters.putString("link", "http://ift.tt/1iQdOc7");
parameters.putString("name", "This is the name of the link set in app.");
parameters.putString("caption", "This is Text that is specified in bt the aoo");
parameters.putString("picture", "http://ift.tt/Q6lwlv");

// Posting my message, maybe here i could add paramterers like icon and a link etc..?
facebook.dialog(MainActivity.this, "feed", parameters,new PostDialogListener());
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{

super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();

}

public abstract class BaseDialogListener implements DialogListener {
@Override
public void onFacebookError(FacebookError e) {


e.printStackTrace();
}
@Override
public void onError(DialogError e) {
e.printStackTrace();
}
@Override
public void onCancel() {
}


}

public class PostDialogListener extends BaseDialogListener {
@Override
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Log.e("","Message posted on the wall.");
MainActivity.this.finish();
} else {
Log.e("","No message posted on the wall.");
MainActivity.this.finish();
}
}
}
}





































































































































































































































































































































































































































































































































No comments:

Post a Comment