Changing Blackberry 10 wallpaper through code is a fairly easy task. In this blog post we will cover two methods of changing wallpaper of Blackberry 10 programatically.
Using Cascades
In cascades we can use HomeScreen class defined inside bb::platform namespace. To link against this class you must have following line in your .pro file
LIBS += -lbbplatform
HomeScreen class has a function setWallpaper which accept object of type QUrl as argument. This function sets the wallpaper to the image pointed by url passed. It returns a bool as status of call.
Now we can write code to change the wallpaper. For simplicity, code will set image as wallpaper from assets directory.
Using Blackberry 10 core API
We can use navigator_set_wallpaper function to set wallpaper of device. This function is defined in bps/navigator.h. It takes const char* pointing to image file as argument and returns BPS_SUCCESS or BPS_FAILURE (with errno set) as result.
Following is the code to use this function to set wallpaper.
Using Cascades
In cascades we can use HomeScreen class defined inside bb::platform namespace. To link against this class you must have following line in your .pro file
LIBS += -lbbplatform
HomeScreen class has a function setWallpaper which accept object of type QUrl as argument. This function sets the wallpaper to the image pointed by url passed. It returns a bool as status of call.
Now we can write code to change the wallpaper. For simplicity, code will set image as wallpaper from assets directory.
bb::platform::HomeScreen homeScr;Blackberry notes for setWallpaper method
bool wallpaperResult=homeScr.setWallpaper(QUrl("asset:///mywallpaper.png"));
The image will be scaled to fit the screen.If the wallpaper image is deleted while it is set as the current wallpaper (say, because the image is an asset in an application that is then deleted), the image will remain the wallpaper until the device is rebooted. At that point, the default wallpaper will be reapplied.The new wallpaper is only applied to the currently active view (personal, work, etc.).Read more...
Using Blackberry 10 core API
We can use navigator_set_wallpaper function to set wallpaper of device. This function is defined in bps/navigator.h. It takes const char* pointing to image file as argument and returns BPS_SUCCESS or BPS_FAILURE (with errno set) as result.
Following is the code to use this function to set wallpaper.
#include <bps/navigator.h>
int main(char **argv,int argc)
{
//beginning of app code
....
int result=navigator_set_image("asset:///mywallpaper.png");
....
//rest of the app code
}
Comments
Post a Comment
Share your wisdom