为黑莓级联自定义推送通知声音和图标10

时间:2015-01-13 07:48:50

标签: blackberry push-notification qml blackberry-10 blackberry-cascades

我使用了来自github的黑莓代码中的pushcollector示例来集成推送通知,我在我的设备中接收通知但是使用默认声音和铃声图标。我需要用我提供的铃声更改默认铃声图标和声音。我的设备是Dev Alpha B,版本是10.2.1.3061

这是我的pushnotfication处理程序代码,但它没有设置声音或图标。任何帮助表示赞赏

void ApplicationUI::pushNotificationHandler(bb::network::PushPayload &pushPayload)
{
    qDebug() << "Received push pushNotificationHandler";

    PushHistoryItem pushHistoryItem(pushPayload.id());

    if (m_pushNotificationService.checkForDuplicatePush(pushHistoryItem)) {
        qWarning() << QString("Duplicate push was found with ID: %0.").arg(pushPayload.id());

        return;
    }

    Push push(pushPayload);
    push.setSeqNum(m_pushNotificationService.savePush(push));

    Notification *notification = new Notification(NOTIFICATION_PREFIX + QString::number(push.seqNum()),this);
    notification->setTitle("Yo");


    PlatformInfo pkinfo;
            QString osVersion=pkinfo.osVersion();
            qDebug() <<"OS full:"<<osVersion;
            osVersion.resize(4);
            qDebug() <<"OS:"<<osVersion;
            float versionValue=10.2;

           if(osVersion.toFloat()>=versionValue)
           {
               qDebug() <<"Notification set:";
               notification->setIconUrl(QUrl("file://" + QDir::currentPath() + "/app/native/assets/Images/customIcon.png"));
               notification->setSoundUrl(QUrl("file://" + QDir::currentPath() + "/app/native/assets/Sounds/customSound.mp3"));
           }
           else
           {
               qDebug() <<"Notification unset OS version is:"<<osVersion.toFloat();
           }

    notification->setBody(QString("New %0 push received").arg(push.fileExtension()));

    InvokeRequest invokeRequest;
    invokeRequest.setTarget(INVOKE_TARGET_KEY_OPEN);
    invokeRequest.setAction(BB_OPEN_INVOCATION_ACTION);
    invokeRequest.setMimeType("text/plain");
    invokeRequest.setData(QByteArray::number(push.seqNum()));
    notification->setInvokeRequest(invokeRequest);
    notification->notify();

    m_model->insert(push.toMap());
    if (pushPayload.isAckRequired()) {
        m_pushNotificationService.acceptPush(pushPayload.id());
    }

}

1 个答案:

答案 0 :(得分:2)

您必须在bar-descriptor.xml中将它们指定为 public 资源,然后使用公共网址而不是私有网址。

最佳方式 - 为公共资源创建单独的文件夹

<强>杆descriptor.xml

<asset path="assets">assets</asset>
<asset path="public" public="true">.</asset>

C ++

notification->setIconUrl(QUrl("file://" + QDir::currentPath() + "/app/public/Images/customIcon.png"));
notification->setSoundUrl(QUrl("file://" + QDir::currentPath() + "/app/public/Sounds/customSound.mp3"));