我有一个使用 Ionic 4 和 Capacitor 编写的 Web/Android 应用程序,我一直在尝试通过 Android 服务(通过电容器插件激活)发出的通知将 Ionic 应用程序重新输入到特定页面,但没有成功。
以下是在服务中创建通知的代码:
private Notification getNotification() {
CharSequence contentTitle = "Fun App Background Mode Running";
CharSequence contentText = "Fun App";
long notificationTime = System.currentTimeMillis();
if (_NFC == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel("funapp", "FunApp", NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(false);
channel.enableVibration(false);
channel.setSound(null,null);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channel.setShowBadge(true);
manager.createNotificationChannel(channel);
}
Intent notificationIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntentWithParentStack(notificationIntent);
PendingIntent pendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); …Run Code Online (Sandbox Code Playgroud)