- Use Download sdk to download the facebook sdk for blackberry.import net.rim.device.api.applicationcontrol.ApplicationPermissions;
- import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
- import net.rim.device.api.system.Application;
- import net.rim.device.api.ui.Field;
- import net.rim.device.api.ui.FieldChangeListener;
- import net.rim.device.api.ui.component.ButtonField;
- import net.rim.device.api.ui.container.MainScreen;
- import com.blackberry.facebook.ApplicationSettings;
- import com.blackberry.facebook.Facebook;
- import com.blackberry.facebook.FacebookException;
- import com.blackberry.facebook.Facebook.Permissions;
- import com.blackberry.facebook.inf.Profile;
- import com.blackberry.facebook.inf.User;
- public class post extends MainScreen{
- public static User user;
- public static Facebook facebook_ ;
- User facebook_user;
- public static Profile[] friends;
- private final static String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
- private final static String APPLICATION_ID =
- private final static String APPLICATION_SECRET =
- private Facebook fb4u;
- public static final String[] USER_PERMISSIONS = new String[] {
- Permissions.OFFLINE_ACCESS, Permissions.EMAIL,
- Permissions.USER_ABOUT_ME, Permissions.USER_BIRTHDAY,
- Permissions.PUBLISH_STREAM };
- public post(){
- final ButtonField btn=new ButtonField("Post");
- add(btn);
- FieldChangeListener listener=new FieldChangeListener() {
- public void fieldChanged(Field field, int context) {
- if(field==btn){
- checkPermissions();
- ApplicationSettings sett=new ApplicationSettings(NEXT_URL, APPLICATION_ID, APPLICATION_SECRET, USER_PERMISSIONS);
- facebook_=Facebook.getInstance(sett);
- synchronized (Application.getEventLock())
- {
- try {
- user = facebook_.getCurrentUser();
- user.publishPost("123", "", "", "", "", "", "");
- } catch (FacebookException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }};
- btn.setChangeListener(listener);
- }
- private static void checkPermissions() {
- ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
- ApplicationPermissions original = apm.getApplicationPermissions();
- 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)) {
- return;
- }
- ApplicationPermissions permRequest = new ApplicationPermissions();
- permRequest.addPermission(ApplicationPermissions.PERMISSION_MEDIA);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_LOCATION_DATA);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_RECORDING);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_INTERNET);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK);
- permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
- boolean acceptance = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);
- if (acceptance) {
- return;
- } else {
- }
- }
- }
Monday, April 16, 2012
Posting to Facebook Wall in Blackberry
Subscribe to:
Post Comments (Atom)
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.
ReplyDeleteits working....
Deletebut im trying i got error ClassDefNotFound...@RINCE
Deleteyou adding facebook jar file or java files of facebook class ?
DeleteI 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..?
ReplyDeleteonly add jad file. also add Log4B jar file. no need to add java files.
DeleteGot IOException from Virtual Machine occurred invoking method , when i run in device , but working fine in blackberry emulator
ReplyDeletePlz help me