4
0
mirror of https://github.com/QuasarApp/SoundBand.git synced 2025-05-12 15:09:35 +00:00

first (not work) notify fersion for android

This commit is contained in:
Andrei Yankovich 2018-10-05 13:00:48 +03:00
parent 75111bd48c
commit 26fca5f464
8 changed files with 66 additions and 11 deletions

@ -50,7 +50,7 @@ DISTFILES += \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat \
java/androidPlayer.java
android/src/NotificationClient.java
HEADERS += \
syncengine.h \

Binary file not shown.

After

(image error) Size: 18 KiB

@ -1,4 +1,4 @@
package SoundBand
package org.quasarapp.sounband;
import android.app.Notification;
import android.app.NotificationManager;
@ -21,7 +21,7 @@ public class NotificationClient extends org.qtproject.qt5.android.bindings.QtAct
m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
m_builder = new Notification.Builder(m_instance);
m_builder.setSmallIcon(R.drawable.icon);
m_builder.setContentTitle("A message from Qt!");
m_builder.setContentTitle("A message from SoundBand!");
}
m_builder.setContentText(s);

@ -1,8 +1,33 @@
#ifdef Q_OS_ANDROID
#include "androidplayer.h"
#ifdef Q_OS_ANDROID
AndroidPlayer::AndroidPlayer(QObject *parent) : QObject(parent)
{
#include <QAndroidJniObject>
AndroidPlayer::AndroidPlayer(QObject *parent)
: QObject(parent) {
connect(this, SIGNAL(notificationChanged()),
this, SLOT(updateAndroidNotification()));
}
QString AndroidPlayer::notification() const {
return m_notification;
}
void AndroidPlayer::setNotification(QString notification) {
if (m_notification == notification)
return;
m_notification = notification;
emit notificationChanged();
}
void AndroidPlayer::updateAndroidNotification() {
QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);
QAndroidJniObject::callStaticMethod<void>("org.quasarapp.sounband.NotificationClient",
"notify",
"(Ljava/lang/String;)V",
javaNotification.object<jstring>());
}
#endif

@ -1,21 +1,34 @@
#ifdef Q_OS_ANDROID
#ifndef ANDROIDPLAYER_H
#define ANDROIDPLAYER_H
#include <QObject>
#ifdef Q_OS_ANDROID
class AndroidPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(QString notification READ notification WRITE setNotification NOTIFY notificationChanged)
private:
QString m_notification;
private slots:
void updateAndroidNotification();
public:
explicit AndroidPlayer(QObject *parent = nullptr);
signals:
QString notification() const;
public slots:
void setNotification(QString notification);
signals:
void notificationChanged();
};
#endif // OS_ANDROID
#endif // ANDROIDPLAYER_H
#endif // OS_ANDROID

@ -60,7 +60,7 @@ bool App::run() {
ctxt->setContextProperty("playListModel", playListModel);
qmlEngine->load(QUrl(QStringLiteral("qrc:/QML/main.qml")));
qmlEngine->load(QUrl(QStringLiteral("qrc:/main.qml")));
if (qmlEngine->rootObjects().isEmpty())
return false;

@ -3,12 +3,17 @@
#include <quasarapp.h>
#include "exaptions.h"
#include "androidplayer.h"
SyncEngine::SyncEngine()
{
sync = new Sync();
sqlApi = sync->getSqlApi();
#ifdef Q_OS_ANDROID
_androidPlayer = new AndroidPlayer(this);
#endif
connect(sync, SIGNAL(networkStateChange()), this, SIGNAL(serversCountChanged()));
connect(sync, SIGNAL(currentPlayListChanged()), this, SIGNAL(currentPlayListNameChanged()));
connect(sync, SIGNAL(currentPlayListChanged()), this, SIGNAL(currentPlayListCountChanged()));
@ -84,7 +89,15 @@ bool SyncEngine::songImageByName(const QString& name, QPixmap &image) {
bool SyncEngine::play(int id){
try{
return sync->play(id);
if (!sync->play(id)) {
return false;
}
#ifdef Q_OS_ANDROID
_androidPlayer->setNotification("sound played!!");
#endif
return true;
}catch(BaseException e){
_lastError = e.what();

@ -4,6 +4,7 @@
#include <QObject>
#include <QPixmap>
class AndroidPlayer;
/**
* @brief The SyncEngine class - this class is interface between syncLine and qml application.
@ -22,6 +23,9 @@ private:
Sync *sync;
MySql * sqlApi;
QString _lastError;
#ifdef Q_OS_ANDROID
AndroidPlayer * _androidPlayer;
#endif
private slots:
void seekChanged(qint64);