User profile location

You can use the UserProfileLocation class to access the current user's country (through a country code and a flag icon) and time zone. These are set by the user in their BlackBerry Messenger profile.

To retrieve a reference to the UserProfileLocation that is associated with the current user, invoke the UserProfile.getUserProfileLocation() method.

Retrieve the user's location

Before you begin: Make sure that you have completed the task, Register your application with the BlackBerry Messenger platform, and that the class that displays the MyUserProfileBoxScreen screen passes in a reference to the BBMPlatformContext object associated with the application.
  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.blackberry.api.bbm.platform.profile.*;
    import net.rim.device.api.system.*;
    import java.util.*;
  2. Create a class that extends MainScreen. In the constructor for this screen class, pass in the application's associated BBMPlatformContext object.
    public class MyUserProfileBoxScreen extends MainScreen
    {
        public MyUserProfileBoxScreen(BBMPlatformContext platformContext) 
        {
    
        }
    }
  3. In the constructor, invoke BBMPlatformContext.getUserProfile() to retrieve a reference to the UserProfile object that is associated with this BBMPlatformContext. The returned instance is the current user's profile.
    UserProfile userProfile = platformContext.getUserProfile();
  4. In the constructor, invoke UserProfile.getUserProfileLocation() to retrieve a reference to the UserProfileLocation object asssociated with this UserProfile.
    UserProfileLocation userProfileLocation = userProfile.getUserProfileLocation();
  5. In the constructor, retrieve the user's country code, country flag icon, and timezone. Note that these fields are read-only.
    String countryCode = userProfileLocation.getCountryCode();
    Bitmap countryIcon = userProfileLocation.getCountryIcon();
    TimeZone timeZone = userProfileLocation.getTimeZone();
Back To Top

Code sample: Retrieving the user's location

The following code sample assumes that the class that displayed the MyUserProfileBoxScreen has passed a reference to the application's associated BBMPlatformContext object into the MyUserProfileBoxScreen constructor.

import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.profile.*;
import net.rim.device.api.system.*;
import java.util.*;

public class MyUserProfileBoxScreen extends MainScreen 
{    
    public MyUserProfileBoxScreen(BBMPlatformContext platformContext) 
    {
        UserProfile userProfile = platformContext.getUserProfile();

        UserProfileLocation userProfileLocation = userProfile.getUserProfileLocation();
								if(userProfileLocation != null) {
            String countryCode = userProfileLocation.getCountryCode();
            Bitmap countryIcon = userProfileLocation.getCountryIcon(); 
            TimeZone timeZone = userProfileLocation.getTimeZone();
        } else {
            // User has not enabled location in profile
        }
    }
}
Back To Top

Was this information helpful? Send us your comments.