我为 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 动态使用它吗