java - 如何从前台服务启动 Flutter 应用程序
问题描述
我有一个 Flutter 应用程序,它运行一个永无止境的前台服务,它的定义如下:
private void startForeground() {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
startForeground(NOTIF_ID, new NotificationCompat.Builder(this,
NOTIF_CHANNEL_ID)
.setOngoing(true)
.setContentTitle("service")
.setContentText("Service is running background")
.setContentIntent(pendingIntent)
.build());
}
我开始这样的服务:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.drawable.smile)
.setContentTitle("App is running in background")
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.build();
startForeground(2, notification);
我的前台服务一直显示通知。
当用户按下前台服务显示的通知时,是否可以启动 Flutter 应用程序,即使 Flutter 应用程序没有在后台运行?谢谢。
解决方案
要Activity
在单击通知时启动,您可以使用PendingIntent
. 您已经在第一个示例中实现了此功能,但这里有一些链接。Android 文档 Stackoverflow 问题
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
builder.setContentIntent(pendingIntent);
推荐阅读
- socrata - 将应用程序令牌和查询功能添加到 api json 端点的正确语法是什么?
- linux - 我有一个登录时间的工作脚本,但如果用户未登录,我会收到错误消息
- datastage - 有没有办法比较两个文件并使用数据阶段生成只有字段级别差异的输出?
- jquery - 为什么我的 jquery 展开/折叠行不起作用?
- java - 将 MimeMessage 对象消息转发为 EML 文件中附件的常规转发格式
- java - 这是相对路径还是绝对路径?
- c# - 使用 PublicSign 签名的 .NET 程序集可以在以后进行真实签名吗?
- visual-studio - ASM 的未定义 .data 部分
- python - 将字符串和数组数据从 CSV 文件转换为 tfrecords 时出错
- angular - Angular JWT 包未正确验证我的令牌