QT/QML Android App,点击通知栏时打开应用程序

2024-05-12

我为 Android 应用程序制作了一个 QT。当我单击平板电脑中上面看到的按钮通知栏时。但是,如果单击通知,我的应用程序将打开/聚焦(不知道)并显示黑色窗口。简单来说怎么做呢。我的代码是:

package org.ays.operation;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.app.PendingIntent;
import android.content.Intent;


public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
{
     private static NotificationManager m_notificationManager;
     private static Notification.Builder m_builder;
     private static NotificationClient m_instance;
     private static PendingIntent contentIntent;
     private static Intent intent;


     public NotificationClient()
     {
         m_instance = this;
     }

     public static  void notify2()
     {
         intent = new Intent(m_instance, NotificationClient.class);
         contentIntent = PendingIntent.getActivity(m_instance, 0, intent,
                                         PendingIntent.FLAG_UPDATE_CURRENT);

         if (m_notificationManager == null) {
             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.setDefaults(Notification.DEFAULT_SOUND);
             m_builder.setContentIntent(contentIntent);
             m_builder.setAutoCancel(true);
         }

         m_builder.setContentText("Bla Bla");
         m_notificationManager.notify(1, m_builder.build());
     }
 }

我来宾,重要的代码是打开/聚焦主应用程序的 PendingIntent。另一种情况是我不想将notify2用作静态。我可以从 Qt/JNI 动态使用它吗


第一种方式:

你必须改变这一行

intent = new Intent(m_instance, NotificationClient.class);

to

Intent intent = new Intent(mActivityInstance, mActivityInstance.getClass());

and

contentIntent = PendingIntent.getActivity(m_instance, 0, intent,
                                     PendingIntent.FLAG_UPDATE_CURRENT);

to

contentIntent = PendingIntent.getActivity(mActivityInstance, 0, intent,
                                     PendingIntent.FLAG_UPDATE_CURRENT);

注意mActivityInstance是你的mainActivity。

我从 C++ 和 JNI 设置 mActivityInstance,如下所示:

const QAndroidJniObject m_JavaNotification("com/falsinsoft/qtandroidtools/AndroidNotification",
                   "(Landroid/app/Activity)V",
                   QtAndroid::androidActivity().object<jobject>());

在我的 AndroidNotification.java 中:

public class AndroidNotification {
private final Activity mActivityInstance;

public AndroidNotification(Activity ActivityInstance)
{
    mActivityInstance = ActivityInstance;
}
}

第二种方式(我不确定这能解决你的问题!): 更改manifest.xml 中的这一行:

    <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="YourProjectName" android:icon="@drawable/icon">

to:

    <application android:hardwareAccelerated="true" android:name="your java class extend from QtActivity" android:label="YourProjectName" android:icon="@drawable/icon">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

QT/QML Android App,点击通知栏时打开应用程序 的相关文章

  • 使用 eclipse 调试 OpenJDK 源代码

    在我的项目中 我想使用 eclipse 调试 OpenJDK 版本 8 的 C C 源代码 为此 我做了以下工作 编译了 OpenJDK8 with debug level slowdebug使用这个readme http hg openj
  • 仅在发布模式下使用 glGenBuffer 时出现未处理的异常 - QT

    我在 Windows 7 上使用 Qt 4 8 发布模式编译项目时遇到了一些问题 调试时一切正常 但在发布时我收到未处理的异常 0xC0000005 访问冲突 我将范围缩小到发生这种情况的行 即生成像素缓冲区的时间 我的第一个猜测是 DLL
  • Qml 和模糊图像

    我想使用 QML 实现模糊效果 我找到了有关 效果 模糊 的参考资料 例子 http qt gitorious org lscunha qt components lscunha qt components blobs d78feec567
  • 仅在内部/外部抚摸路径?

    Given a QPainterPath http qt project org doc qt 4 8 qpainterpath html如何仅在路径的内侧或外侧边缘 或非闭合路径的左侧或右侧 描边路径 QPainter strokePat
  • 如何在 Qt Creator 中编辑 QtWebKit 的右键上下文菜单?

    好吧 这是我的困境 我正在使用 Qt Creator 制作一个使用 Webkit 的简单应用程序 我认为 Qt Creator 会有一种简单的方法来使用信号和槽编辑器编辑右键单击上下文菜单 但事实证明这不是真的 我知道 webkit 有与上
  • 用 C++/Qt 编写的程序中的 RTF / doc / docx 文本提取

    我正在写一些程序Qt https en wikipedia org wiki Qt 28software 29 C 我需要从中读取文本微软Word https en wikipedia org wiki Microsoft Word RTF
  • QStyledItemDelegate 绘制自定义小部件失败

    在我的一个项目中 我使用的是QTableWidget为了显示一些复杂的计算结果 为了提高表格的可读性 我需要在单个表格单元格内显示两个对齐的值 后来我想通过使用颜色或箭头等来进一步自定义小部件 为此我源自QStyledItemDelegat
  • QT:删除QGridLayout中QLabel之间的空格

    我将一些具有不同颜色的 QLabels 添加到 QGridLayout 作为 QWidget 的布局 现在我在每个 Qlabel 与下一个 Qlabel 之间有一个间距 我想将其删除 我尝试将标签的边距设置为 0 将 GridLayout
  • 如何在Android上创建原生C++库?

    我需要用C 编写一个动态链接库 供Android上的Java使用 据我所知 它应该是 so 库 但我不知道该怎么做 我尝试了 Cygwin 但它崩溃了 海湾合作委员会1 cpp usr lib gcc i686 pc cygwin 4 3
  • 清除pyqt中布局中的所有小部件

    有没有办法清除 删除 布局中的所有小部件 self plot layout QtGui QGridLayout self plot layout setGeometry QtCore QRect 200 200 200 200 self r
  • C++ SQL 查询构建库

    我正在寻找一个提供与 c SelectQueryBuilder 库类似功能的 c 库 http www codeproject com Articles 13419 SelectQueryBuilder Building complex a
  • JNI - 如何从 C++ 或 C 回调到 Java?

    我有调用本机 C C 代码的 Java 应用程序 C C 代码需要回调到 Java 中 你能给我一些如何做到这一点的例子吗 有许多有效的方法可以从 C C 回调到 Java 我将向您展示一种使用 C 的技术 易于调整 C 的环境 该技术使得
  • DP5 7.0 - 向待处理意图添加额外内容是否会失败?

    在跟踪器上添加链接的问题 因此 我今天在我的 Nexus 5X 上安装了 DP5 Android 7 0 版本 我一直在开发一个应用程序 它使用 Android 的 AlarmManager 类在特定时间安排本地通知 在此版本之前 代码在运
  • 如何doxygen注释Qt属性?

    我想将 Doxygen 注释附加到我的 Q PROPERTY 例如 song h class Song public QObject Q OBJECT private Q PROPERTY QString title READ title
  • 如何使用NotificationCompat.Builder和startForeground?

    简短的问题 我正在尝试使用 NotificationCompat Builder 类来创建将用于该服务的通知 但由于某种原因 我要么看不到该通知 要么在该服务应该取消时无法取消它被破坏 或停止在前台 my code Override pub
  • 如何在 Qt 应用程序中嵌入 Python 解释器?

    有没有一种简单的方法可以将 Python 解释器嵌入到 Qt 应用程序中 如果可能的话 我希望有一个跨平台的解决方案 这就是目的PythonQt http pythonqt sourceforge net 它支持 Windows Linux
  • 为什么某些 Android 手机会导致我们的应用程序抛出 java.lang.UnsatisfiedLinkError?

    我们正在经历一个java lang UnsatisfiedLinkError在市场上使用我们应用程序的一些 Android 手机上 问题描述 static System loadLibrary stlport shared C STL Sy
  • Qt中用于线程间通信的类设计

    问题陈述 用相机跟踪物体并相应地移动相机的方位角和仰角 Process 相机获取物体的图像 处理相机的每一帧以查找物体 应该被跟踪 并将每帧中生成的信息传递给机械设备 万向节 以平移和倾斜方式移动摄像机 Design 主 Gui 在一个线程
  • Android:AlarmManager用于调用Service来通知用户

    Edit在我的清单中添加这一行解决了我的问题 Service创造得很好
  • 如何在Android中使用QML - QWebView

    我想在 Android 中部署一个 YouTube 应用程序 但它只能在我的电脑上运行 在安卓上不起作用 它不加载任何视频 问题仅出在 QWebView 上 我使用了与此类似的代码 http doc qt io archives qt 5

随机推荐