这是我的清单
<service android:name=".fcm.PshycoFirebaseMessagingServices">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".fcm.PshycoFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.
这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See …Run Code Online (Sandbox Code Playgroud) 我正在使用Firebase控制台向用户发送通知.但是,我想让用户禁用通知.我怎样才能禁用它们?
只有当应用程序位于前台时,我才能通过FirebaseMessagingService处理(和停止)通知.但是,当应用程序处于后台时,我无法停止通知.
我正在开发一个电子邮件应用程序,我希望用户在收到新电子邮件后立即收到推送通知。为此,我正在使用 FCM。我刚刚通过以下链接尝试使用 fcm 推送通知:https : //www.youtube.com/watch?v= XijS62iP1Xo&t=6s 以测试 fcm 提供的功能。但我面临的问题是,当应用程序处于前台或后台时,设备会收到推送通知,但在应用程序关闭时(从任务管理器滑动或清除),它不会收到任何推送通知。我不知道如何通过 fcm 实现这一目标?我想像 WhatsApp 和 facebook 一样接收推送通知。
各种帮助表示赞赏。提前致谢。
当用户点击推送通知时,我试图用网址打开浏览器,我在stackoverflow中搜索,我发现这个
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)
但它不适合我,当我把通知没有出现,我调试它,它只抛出类文件编辑器没有错误或任何东西.
这是代码
public void mostrarNotificacion(Context context, String body,String title, String icon, String url,String superior)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notManager = (NotificationManager) context.getSystemService(ns);
int icono = R.drawable.mydrawable;
CharSequence textoEstado = superior;
long hora = System.currentTimeMillis();
Notification notif = new Notification(icono, textoEstado, hora);
Context contexto = context.getApplicationContext();
CharSequence titulo = title;
CharSequence descripcion = body;
PendingIntent contIntent;
if(url.equalsIgnoreCase("NULL"))
{
Intent notIntent = new Intent(contexto,MainActivity.class);
contIntent = PendingIntent.getActivity(
contexto, 0, notIntent, 0);
} …Run Code Online (Sandbox Code Playgroud) 我使用firebase来构建我的项目.
它还将使用FCM(firebase云消息).
但有一个问题.
当app在后台时,我无法处理FCM(创建我的自定义通知).
官方网站教程说
案例1:应用前台 - >覆盖"onMessageReceived()"来创建自定义通知.
案例2:应用程序背景 - >系统将直接创建通知.我们不需要也不能做任何事情.因为在这种情况下它不会触发"onMessageReceived()".
但是,如果我在应用程序是后台时无法执行任何操作,则无法创建自定义通知.(例如,在用户单击通知后,它将弹出一个窗口以显示详细信息.)
那么,当应用程序处于后台时,如何使用FCM处理通知?