Download file from the internet and update media DB

This set of functions will help you to download file from the internet and update the media database to make the newly downloaded file visible in media galleries on the device. Additionally, download progress callback is invoked and displaying progress in the console logs.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//      PRIVILEGES NEEDED TO BE SET IN tizen-manifest.xml:
//      http://tizen.org/privilege/download
//      http://tizen.org/privilege/mediastorage
//      http://tizen.org/privilege/externalstorage
//      http://tizen.org/privilege/content.write
#include <download.h>
#include <media_content.h>
#include <stdlib.h>
#include <dlog.h> //for logging purposes
//Callback to be called when download is in progress...
void download_progress_callback(int download_id, unsigned long long received, void *user_data)
{
    download_state_e state;
    unsigned long long size = 0;
    if ((download_get_state(download_id, &state) == DOWNLOAD_ERROR_NONE)
        && (state >= DOWNLOAD_STATE_DOWNLOADING))
    {
        if ((download_get_content_size(download_id, &size) == DOWNLOAD_ERROR_NONE)
            && (size > 0))
        {
            dlog_print(DLOG_INFO, LOG_TAG, "%llu%% of the file received...", (received*100 / size));
        }
        else
        {
            dlog_print(DLOG_INFO, LOG_TAG, "Problem with getting file size. %llu%% bytes received...", received);
        }
    }
}
//Callback to be called on the download state change.
void download_state_callback (int download_id, download_state_e state, void *user_data)
{
    if(state == DOWNLOAD_STATE_COMPLETED)
    {
        char *path = NULL;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX