Advertisement
alishaik786

Facebook.java

Feb 8th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. //======================StaratUp.java
  2.  
  3. import net.rim.device.api.ui.UiApplication;
  4.  
  5. public class StartUp extends UiApplication
  6. {
  7. public static void main(String args[])
  8. {
  9. StartUp start=new StartUp();
  10. start.enterEventDispatcher();
  11. }
  12. public StartUp()
  13. {
  14. pushScreen(new FaceBookScreen());
  15. }
  16. }
  17.  
  18. //=====================================FaceBookScreen.java
  19.  
  20. public final class FaceBookScreen extends MainScreen implements FieldChangeListener
  21. {
  22. String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
  23. String APPLICATION_ID = "";
  24. String APPLICATION_SECRET = "";
  25. String[] PERMISSIONS = Facebook.Permissions.USER_DATA_PERMISSIONS;
  26. ButtonField btn;
  27.  
  28. public FaceBookScreen()
  29. {
  30. setTitle("Loading Screen");
  31. createGUI();
  32. }
  33.  
  34. private void createGUI()
  35. {
  36. btn=new ButtonField("Face Book");
  37. btn.setChangeListener(this);
  38. add(btn);
  39. }
  40. public void fieldChanged(Field field, int context)
  41. {
  42. shareWithFaceBook("This is the Blackberry sample application");
  43. }
  44. public void shareWithFaceBook(String COMMON_SHARED_DATA)
  45. {
  46. Facebook facebook = null;
  47. try
  48. {
  49. ApplicationSettings sett=new ApplicationSettings(NEXT_URL, APPLICATION_ID, APPLICATION_SECRET, Permissions.ALL_PERMISSIONS);
  50. facebook=Facebook.getInstance(sett);
  51. synchronized (UiApplication.getUiApplication().getAppEventLock())
  52. {
  53. User user = facebook.getCurrentUser();
  54. String result = user.publishPost("Check out this details from ABC\n", "http://www.google.com/", "https://www.google.com/intl/en_com/images/srpr/logo3w.png", "Hi,I got the above details from ABC Blackberry app", "http://www.google.com", COMMON_SHARED_DATA, "");
  55. if ((result != null) && !result.trim().equals(""))
  56. {
  57. int k=Dialog.ask(Dialog.D_OK,"Details successfully shared with Facebook");
  58. if(k==Dialog.D_OK)
  59. {
  60. if (Dialog.ask("Please choose:", new String[] { "Exit", "Logout & Exit" }, 0) == 0)
  61. {
  62. //nothing;
  63. }
  64. else
  65. {
  66. facebook.logout(true);
  67. }
  68. }
  69. }
  70. else
  71. {
  72. facebook.logout(true);
  73. }
  74. }
  75. }
  76. catch (Exception e)
  77. {
  78.  
  79. facebook.logout(true);
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement