我尝试发送Firebase云消息传递通知,但很少有人收到这些通知。有人可以调查我的问题吗?
以下是我的FirebaseMessagingService代码:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
generateNotification(remoteMessage.getNotification().getBody(),remoteMessage.getNotification().getTitle());
}
private void generateNotification(String body,String title)
{
Intent intent=new Intent(this, Home_Activity.class);
intent.setFlags(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);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(body);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
}
}
以下是我的FirebaseInstanceIdService代码:控制台中每次刷新时令牌也不会打印的一些方式
public class MyFirebaseServiceInstanceId extends FirebaseInstanceIdService {
private static final String REG_TOKEN="REG_TOKEN";
@Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
@Override
public void onTokenRefresh()
{
String strRecent_Token=FirebaseInstanceId.getInstance().getToken();
if(strRecent_Token!=null)
Log.d(REG_TOKEN,strRecent_Token);
else
Log.d(REG_TOKEN,"Generated null token");
}
}
以下是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.udayrepo.classelearn">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".Home_Activity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".firebase.MyFirebaseServiceInstanceId">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".firebase.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
有人可以帮助我在这里我想念的吗?