标签: firebase-notifications

如何在Manifest中设置Android Firebase通知?

我正在尝试设置Firebase通知.我在应用级别和根级别build.gradle中进行了更改.但是,它仍然在MyFirebaseMessagingService的Manifest中给出了错误.错误是未解决的类.

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">


        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".s" />
    <activity android:name=".im" />
    <activity android:name=".Main2Activity" />
    <activity android:name=".sactivity" />
    <service
        android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <activity
        android:name=".ScrollingActivity"
        android:label="@string/title_activity_scrolling"
        android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
Run Code Online (Sandbox Code Playgroud)

android manifest firebase firebase-notifications

5
推荐指数
1
解决办法
8535
查看次数

FirebaseMessagingService:如果应用未运行,则intent.putExtra()不起作用

EDIT3:好的,我发现了问题:如果应用程序被杀死,则同时发送data 发送都notification不会触发onMessageReceivednotification如果目标设备是android,则需要将其设置为null。

这确实是一种愚蠢的行为。

原始帖子:

notificationBuilder启动应用程序后,我可以成功地从传递给活动的意图中检索捆绑包。

但是,如果我终止了该应用程序,则通知仍然有效,但GetExtras()意图上的则为null。

在我的FirebaseMessagingService孩子班上:

@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
     Intent intent  = new Intent(this, MainActivity.class);        
     intent.putExtra("key_1","value");
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    //also tried with  PendingIntent.FLAG_CANCEL_CURRENT


     Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("title")
            .setContentText("messageBody")
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

}
Run Code Online (Sandbox Code Playgroud)

当应用被杀死时,firebaseMessagingService甚至无法写入文件。它不会崩溃,它会生成并显示通知,但是对磁盘所做的任何操作均不起作用。

编辑:我已替换onMessageReceived方法的内容,如下所示:

@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{ …
Run Code Online (Sandbox Code Playgroud)

android android-intent firebase firebase-notifications

5
推荐指数
1
解决办法
3107
查看次数

Firebase发送多个推送通知,而不是堆叠或替换

我正在尝试使用新的推送通知堆栈或将其替换为系统托盘中的android.

我不知道如何执行此操作,因为推送通知正在发送回数据和通知对象,并且据我所知,通知直接发送到系统托盘.如果是这样,我如何阻止通知独立出现.有些用户会收到5-10个通知,而且会继续推升.

编辑:

我尝试了collapse_key,但它仍然没有用相同的密钥替换先前的通知......我在这里做错了吗?

method: 'POST',
                            uri: 'https://gcm-http.googleapis.com/gcm/send',
                            headers: {
                                'Content-Type': 'application/json',
                                'Authorization': authorize //GOOGLE API KEY
                            },

                            body: JSON.stringify({
                                "registration_ids": [otherUserResult.reg_id],

                                "collapse_key": "follow",
                                "data": {
                                    "notifyToUserId": to,
                                    "notifyFromId": from,
                                    "notifyMsg": msg,
                                    "notifyItemPicture": itemPic,
                                    "notifyItemName": itemName,
                                    "notifyFromName": fromName,
                                    "notifyType": type,
                                    "dateNotified": dateNotified


                                },
                                "notification": {
                                    "title": fromName,
                                    "body": notifyMsg,
                                    "icon"  : "ic_pushnotify"
                                },
                                "priority": "high",
                                "content_available": true
Run Code Online (Sandbox Code Playgroud)

notifications android push-notification firebase firebase-notifications

5
推荐指数
1
解决办法
1306
查看次数

当前景中的应用程序时,iOS Swift接收推送通知

这是我在前台app时用来接收推送通知的代码

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
{
     completionHandler([UNNotificationPresentationOptions.Alert,UNNotificationPresentationOptions.Sound,UNNotificationPresentationOptions.Badge])
}
Run Code Online (Sandbox Code Playgroud)

但我的问题是我的通知包含[NSObject:AnyObject]值.如何接收类似的背景通知

push ios firebase-notifications unusernotificationcenter

5
推荐指数
1
解决办法
4885
查看次数

在Android中FCM通知是否可靠?

我正在我的android应用程序中处理FCM通知.我遇到的问题是有些用户没有收到通知,而且那些相应的通知正在丢失.我只是想知道FCM通知可以在什么情况下使用错过了?

有时消息会在几秒钟内收到,有时几分钟后(甚至可能超过10分钟甚至20分钟!),有时根本不会...

这是随机发生的 - 例如,可以立即收到消息,并且只有在10分钟后才会收到消息.

我已将消息的优先级设置为高,并将生存时间设置为最大,以确保不丢弃消息.

我没有时间延迟FCM,但我想知道这些通知在哪些情况下丢失?

android push-notification firebase-notifications

5
推荐指数
0
解决办法
622
查看次数

当应用程序在后台通过api时显示Firebase消息onReceived的通知

我已经构建了一个聊天应用程序 它工作正常.两个用户都可以轻松聊天,但我得到的地方是,如果一个用户的应用程序处于后台并且屏幕关闭,则无法通知用户该收到的消息.

我现在想要的是在我的应用程序中,当userA向userB发送消息,而userB mobile空闲但应用程序在后台运行时,userB可以获得有关该消息的通知.和userB可以打开聊天活动并阅读消息.

我的firebase通知正在从firebase控制台工作,但我不知道如何调用实例ID并将其从api发送到特定设备,特定用户获取有关收到的消息的通知,当应用程序屏幕关闭且应用程序在后台状态下运行时.我应该如何实现它?

我这里有我的firebase实例id服务类:

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";

    @Override
    public void onTokenRefresh() {

        //Getting registration token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();

        //Displaying token on logcat
        Log.d(TAG, "Refreshed token: " + refreshedToken);
    }

    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server
        //Not required for current project
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的MyFirebase Messaging Service Class

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage …
Run Code Online (Sandbox Code Playgroud)

android android-notifications firebase firebase-notifications

5
推荐指数
2
解决办法
1万
查看次数

适用于Firebase的云功能:向Android设备发送无法正常工作的主题通知

我正在遵循Udacity的这个教程,其中使用Cloud Functions for Firebase来更改引用数据的数据.我想使用类似的功能,但是向订阅主题的用户发送推送通知.

这是我正在使用的功能.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/messages/{pushId}/text').onWrite((event) => {
    const data = event.data;
    console.log('Message received');
    if(!data.changed()){
        console.log('Nothing changed');
        return;
    }else{
        console.log(data.val());
    }

    const payLoad = {
        notification:{
            title: 'Message received',
            body: 'You received a new message',
            sound: "default"
        }
    };

    const options = {
        priority: "high",
        timeToLive: 60*60*2
    };

    return admin.messaging().sendToTopic("Message_Notifications", payLoad, options);
});
Run Code Online (Sandbox Code Playgroud)

查看Firebase函数日志,我可以看到在向数据库添加新值时调用该函数.我正在订阅主要活动中的主题

FirebaseMessaging.getInstance().subscribeToTopic("Message_Notification");
Run Code Online (Sandbox Code Playgroud)

几个小时后,我可以在firebase通知控制台的主题列表中看到该主题.我从那里发送通知并且有效.

每次添加新邮件时,我都需要做些什么才能显示通知?

任何建议表示赞赏.我是Firebase的新手.因此,如果有更好的博客/帖子,请重定向我,以便我可以了解更多.

提前致谢.

android firebase google-cloud-functions firebase-cloud-messaging firebase-notifications

5
推荐指数
1
解决办法
3164
查看次数

如何在android中使用firebase获取推送通知的设备ID

我找到了这个解决方案,我认为这不是通知所需的ID,请通过一些示例告诉我:

import android.provider.Settings.Secure;

private String androidIdd = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
Run Code Online (Sandbox Code Playgroud)

我想我不需要一个Android id.我只想获取Firebase Notification或GCM的设备唯一ID.

android firebase firebase-cloud-messaging firebase-notifications

5
推荐指数
1
解决办法
2万
查看次数

5
推荐指数
1
解决办法
844
查看次数

如何在特定时间从Firebase触发通知?

我正在做一个健身应用程序,在该应用程序中,我必须从存储在Firebase中的日期起的特定时间通知用户。

例如:我正在Firebase数据库中保存今天的时间戳,说“ start_at”:“ timestamp”,现在我必须从存储的日期(时间戳)起1周后发送通知。

它类似于cron功能。我不知道该如何在Firebase中实现它。

有人在帮我吗?

ios firebase swift firebase-notifications

5
推荐指数
1
解决办法
1302
查看次数