Android 未收到Firebase云消息通知

Android 未收到Firebase云消息通知,android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,我曾尝试使用Firebase云消息每天在同一时间以手动和编程方式发送通知,但问题是我无法让通知正常工作。我已经尝试向每台设备发送通知,并使用令牌将其发送到我的手机,但似乎没有任何效果。 这是我的AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> build.gradle(应用程序): build.gradle(项目): 其他可能有用的信息: 我在Firebase中创建了这个

我曾尝试使用Firebase云消息每天在同一时间以手动和编程方式发送通知,但问题是我无法让通知正常工作。我已经尝试向每台设备发送通知,并使用令牌将其发送到我的手机,但似乎没有任何效果。 这是我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
build.gradle(应用程序):

build.gradle(项目):

其他可能有用的信息:

  • 我在Firebase中创建了这个应用程序,它与Android Studio中的应用程序具有相同的包名
  • 我已经下载了google-services.json并将其移动到应用程序目录中
  • 我的设备上安装了Google Play服务
  • 我在后台、前台、设备锁定、解锁、应用打开、关闭等方面尝试了应用程序
  • 我已经为我的项目下载了Google Play services SDK
我想我已经尝试了我在Firebase指南和Stack Overflow上找到的所有东西,我希望你能找到我错的地方,谢谢

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

<application
    android:allowBackup="true"
    android:fullBackupContent="true"
    android:icon="@mipmap/app_logo"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:configChanges="locale">
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-7502636795711960~9738222249"/>
    <activity android:name=".Aiuta"
        android:screenOrientation="portrait"
        android:configChanges="locale"/>
    <activity android:name=".DatiRegione"
        android:screenOrientation="portrait"
        android:configChanges="locale"/>
    <activity android:name=".Regioni"
        android:screenOrientation="portrait"
        android:configChanges="locale"/>
    <activity android:name=".Lingua"
        android:screenOrientation="portrait"
        android:configChanges="locale"/>
    <activity android:name=".Statistiche"
        android:screenOrientation="portrait"
        android:configChanges="locale"/>
    <activity android:name=".Impostazioni"
        android:screenOrientation="portrait"
        android:configChanges="locale"/>
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:configChanges="locale">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name="com.al24.covid_19.NotificationService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

    <service android:name="com.al24.covid_19.IdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </receiver>

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@mipmap/app_logo" />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id" />
</application>
public class NotificationService extends FirebaseMessagingService {
private void sendNotification(String messagebody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
            PendingIntent.FLAG_ONE_SHOT);

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

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 , notificationBuilder.build());
}

private void sendSnackbar(String messagebody)
{
    Toast.makeText(this,"Notified",Toast.LENGTH_LONG).show();
}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Toast.makeText(this,"Message Received",Toast.LENGTH_LONG).show();

    Log.d("Notification Received",remoteMessage.getNotification().getBody());

    sendNotification(remoteMessage.getNotification().getBody());
    sendSnackbar(remoteMessage.getNotification().getBody());
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation platform('com.google.firebase:firebase-bom:26.0.0')

implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'
}
buildscript {

repositories {
    google()
    jcenter()
    
}
dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath 'com.google.gms:google-services:4.3.4'  // Google Services plugin
    
}
}