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.
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
}
}
}
Next topic: Defining service listeners
Previous topic: Code sample: Removing an item from the user's profile box