List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Monday, April 16, 2012

Posting to Facebook Wall in Blackberry


  1. Use Download sdk to download the facebook sdk for blackberry.

    import net.rim.device.api.applicationcontrol.ApplicationPermissions;
  2. import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
  3. import net.rim.device.api.system.Application;
  4. import net.rim.device.api.ui.Field;
  5. import net.rim.device.api.ui.FieldChangeListener;
  6. import net.rim.device.api.ui.component.ButtonField;
  7. import net.rim.device.api.ui.container.MainScreen;
  8. import com.blackberry.facebook.ApplicationSettings;
  9. import com.blackberry.facebook.Facebook;
  10. import com.blackberry.facebook.FacebookException;
  11. import com.blackberry.facebook.Facebook.Permissions;
  12. import com.blackberry.facebook.inf.Profile;
  13. import com.blackberry.facebook.inf.User;
  14. public class post extends MainScreen{
  15.         public static User user;
  16.         public static Facebook facebook_ ;
  17.         User facebook_user;
  18.         public static Profile[] friends;
  19.         private final static String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
  20.         private final static String APPLICATION_ID =
  21.         private final static String APPLICATION_SECRET =
  22.         private Facebook fb4u;
  23.         public static final String[] USER_PERMISSIONS = new String[] {
  24.                         Permissions.OFFLINE_ACCESS, Permissions.EMAIL,
  25.                         Permissions.USER_ABOUT_ME, Permissions.USER_BIRTHDAY,
  26.                         Permissions.PUBLISH_STREAM };
  27.            
  28.         public post(){
  29.                
  30.                
  31.                
  32.                 final ButtonField btn=new ButtonField("Post");
  33.                 add(btn);
  34.        
  35.                   FieldChangeListener listener=new FieldChangeListener() {
  36.                                 public void fieldChanged(Field field, int context) {
  37.                                   if(field==btn){
  38.                                          
  39.                                          checkPermissions();
  40.                                  ApplicationSettings sett=new ApplicationSettings(NEXT_URL, APPLICATION_ID, APPLICATION_SECRET, USER_PERMISSIONS);
  41.                                  facebook_=Facebook.getInstance(sett);
  42.                                
  43.                                
  44.                                  synchronized (Application.getEventLock())
  45.                                  {
  46.                                          try {
  47.                                                                 user = facebook_.getCurrentUser();
  48.                                                                 user.publishPost("123", "", "", "", "", "", "");
  49.                                                                
  50.                                                         } catch (FacebookException e) {
  51.                                                                 // TODO Auto-generated catch block
  52.                                                                 e.printStackTrace();
  53.                                                         }
  54.                                                
  55.                                  }
  56.                                        
  57.                                   }
  58.                          
  59.                                 }};
  60.                  
  61.                                 btn.setChangeListener(listener);
  62. }
  63.         private static void checkPermissions() {
  64.                 ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
  65.                 ApplicationPermissions original = apm.getApplicationPermissions();
  66.                 if ((original.getPermission(ApplicationPermissions.PERMISSION_MEDIA) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_LOCATION_DATA) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_RECORDING) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_INTERNET) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_EMAIL) == ApplicationPermissions.VALUE_ALLOW)) {
  67.                         return;
  68.                 }
  69.                 ApplicationPermissions permRequest = new ApplicationPermissions();
  70.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_MEDIA);
  71.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_LOCATION_DATA);
  72.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_RECORDING);
  73.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
  74.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
  75.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
  76.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_INTERNET);
  77.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK);
  78.                 permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
  79.                 boolean acceptance = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);
  80.                 if (acceptance) {
  81.                         return;
  82.                 } else {
  83.                 }
  84.                 }
  85.         }



        

7 comments:

  1. is it working?..I have same code but i got exception java.lang.NoClassDefFoundError ..Facebook class cant found why what is the reson pl help me..already im spending 7 days on this issue.

    ReplyDelete
    Replies
    1. but im trying i got error ClassDefNotFound...@RINCE

      Delete
    2. you adding facebook jar file or java files of facebook class ?

      Delete
  2. I am also getting java.lang.NoClassDefFoundError.. I am using FacebookBlackBerrySDK-v0.8.25.jar file. Do I have to add java files instead of .jar? If yes, How to add those java files in my application? Can you please help me..?

    ReplyDelete
    Replies
    1. only add jad file. also add Log4B jar file. no need to add java files.

      Delete
  3. Got IOException from Virtual Machine occurred invoking method , when i run in device , but working fine in blackberry emulator

    Plz help me

    ReplyDelete