#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
Result newsInitResult = newsInit();
if (newsInitResult != 0)
{
printf("Unable to initialise news:u, error %08lx\n", newsInitResult);
}
else
{
const char *message = "Hello, world";
const char *title = "Title of message";
// When going from utf-8 to utf-16, you need enough room in the buffer for double the
// string length (hence the * sizeof(uint16_t)), plus two bytes
// (another sizeof(uin16_t)) for a utf-16 null terminator.
const size_t messageLen = strlen(message);
const size_t message16Len = (messageLen * sizeof(u16)) + sizeof(u16);
u16 *message16Buffer = malloc(message16Len);
const size_t titleLen = strlen(title);
const size_t title16Len = (titleLen * sizeof(u16)) + sizeof(u16);
u16 *title16Buffer = malloc(title16Len);
if (message16Buffer && title16Buffer)
{
memset(message16Buffer, 0, message16Len);
utf8_to_utf16(message16Buffer, (u8 *)message, messageLen);
memset(title16Buffer, 0, title16Len);
utf8_to_utf16(title16Buffer, (u8 *)title, titleLen);
NEWSU_AddNotification(title16Buffer, titleLen, message16Buffer, messageLen, NULL, 0, false);
printf("Added a notification. Check the HOME menu to\nsee what it says!\n");
}
else
printf("Unable to allocate memory for string buffer(s).\n");
newsExit();
free(message16Buffer);
free(title16Buffer);
}
printf("Press START to exit.\n");
while (aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();
if (hidKeysDown() & KEY_START)
break;
gfxFlushBuffers();
gfxSwapBuffers();
}
gfxExit();
return 0;
}