Skip to main content

Change Blackberry 10 wallpaper programatically

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.
bb::platform::HomeScreen homeScr;
bool wallpaperResult=homeScr.setWallpaper(QUrl("asset:///mywallpaper.png"));
Blackberry notes for setWallpaper method
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

Popular posts from this blog

Decoding JPEG image file using libavcodec

I got a chance to work on a video encoding application that decodes series of jpeg files and convert them into ogg theora video file. I used the infamous libavcodec library that is used in FFMPEG . I decided to write blog posts explaining how I decode jpeg images and convert them into ogg video file. This is the first part and in this I will explain how to decode jpeg images using libavcodec. To learn how to write decoded images as a ogg video file please read http://random-stuff-mine.blogspot.com/2017/07/encoding-raw-images-to-ogg-theora-video.html Before reading this blog post you must be aware of using and setting up libavcodec. I highly recommend this tutorial to get basics of using libavcodec http://www.ffmpeg.org/doxygen/0.6/api-example_8c-source.html Allocating input format context We will first allocate input format for reading the file. We will use avformat_open_input function that will allocate AVFormatContext structure passed to it , the function detects input typ...

Multithreaded C# TCP server to handle multiple clients

I decided to write a minimal multithreaded TCP based server as a blog post. Following class can serve as a skeleton for any small or large scale multithreaded TCP socket server. It do not contain much error handling , it is only to give an idea that how multithreaded server works and how it can process multiple clients using threading. using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.Collections.Generic; namespace RandomStuffMine { public class MTServer {     public int Port{get;set;}     public Socket ServerSocket{get;set;}     private List<Client> Clients=new List<Client>();     private bool runServer=true;     public MTServer(int port)     {         Port=port;         ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);     }   ...

CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information

I created a new Blazor Server app in Visual Studio 2019 and tried to run it. But I was getting this error CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. I couldn't find any reason or solution to this problem. I tried creating the project multiple times but same error. I created a new .Net Core Web App and added a new razor component and included that component in a razor page (cshtml file) like this @(await Html.RenderComponentAsync<GeofenceWork>(RenderMode.ServerPrerendered)) and <component type="typeof(GeofenceWork)" render-mode="serverprerendered" /> As soon as I navigate to this page that has component added I got the same error: CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. This was very frustrating. After hours of trying and searching I figured out the solution.  ...