Android一次只能运行一个Firebase消息服务
我正在使用两个firebase云消息服务提供商在我的应用程序中发送和接收推送通知。这是客户的要求,因此我不能反对 问题是,在我添加第二个fcm提供程序服务之前,第一个fcm提供程序服务(Nifty SDK)运行得非常好。我没有删除任何与第一个相关的代码。此外,我只使用一个FirebaseMessagingService类(我应该这样做)来处理来自两个SDK的所有传入通知 下面是它们的相应清单文件数据的相关区块:Android一次只能运行一个Firebase消息服务,android,firebase-cloud-messaging,Android,Firebase Cloud Messaging,我正在使用两个firebase云消息服务提供商在我的应用程序中发送和接收推送通知。这是客户的要求,因此我不能反对 问题是,在我添加第二个fcm提供程序服务之前,第一个fcm提供程序服务(Nifty SDK)运行得非常好。我没有删除任何与第一个相关的代码。此外,我只使用一个FirebaseMessagingService类(我应该这样做)来处理来自两个SDK的所有传入通知 下面是它们的相应清单文件数据的相关区块: <receiver android:name=".service
<receiver android:name=".service.ConnectionReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<receiver android:name=".service.RemovedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="jp.croomplus.crewmart" />
</intent-filter>
</receiver>
<service android:name=".service.CustomNiftyMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- 通知エリアに表示されるアイコンの設定 -->
<meta-data
android:name="smallIcon"
android:resource="@mipmap/ic_launcher" />
<!-- 通知エリアに表示されるアイコンカラーの設定 -->
<meta-data
android:name="smallIconColor"
android:value="@color/colorAccent" />
<!-- 通知エリアにプッシュ通知を複数表示する設定 0:最新のみ表示 , 1:複数表示 -->
<meta-data
android:name="notificationOverlap"
android:value="1" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher" />
<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/push_channel_id" />
<!-- PPSDK related -->
<!-- ジオエリア検知情報をユーザーへコールバックするレシーバークラス -->
<receiver
android:name="jp.co.evergreen.listener.PPSDKGeoAreaListener"
android:exported="false">
<intent-filter>
<!-- ジオエリア検知イベントアクション名 -->
<action android:name="jp.profilepassport.android.GEOAREA" />
</intent-filter>
</receiver>
<!-- 各種バッチ用レシーバークラス -->
<receiver
android:name="jp.profilepassport.android.tasks.PPScheduleReceiver">
<intent-filter>
<!-- アプリ更新イベント -->
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
<intent-filter>
<!-- 時間変更イベント -->
<action android:name="android.intent.action.TIME_SET" />
<!-- Locale変更イベント -->
<action android:name="android.intent.action.LOCALE_CHANGED" />
<!-- 起動イベント -->
<action android:name="android.intent.action.BOOT_COMPLETED" />
<!-- Bluetooth状態変更イベント -->
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
<!-- 位置情報使用状態変更イベント -->
<action android:name="android.location.PROVIDERS_CHANGED" />
</intent-filter>
</receiver>
<!-- Push通知開封イベント用Service -->
<service android:name="jp.profilepassport.android.notification.PPNotificationService" />
<!-- ジオエリア検知用BroadcastReceiver -->
<receiver android:name="jp.profilepassport.android.geoarea.receiver.PPGeoAreaReceiver" />
<!-- WiFi検知用Service -->
<service android:name="jp.profilepassport.android.wifi.service.PPWifiScanService" />
<!-- PPSDKのJobScheduler実行Service -->
<service
android:name="jp.profilepassport.android.schedule.PPJobService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<!-- ログ作成用JobScheduler実行Service -->
<service
android:name="jp.profilepassport.android.logger.PPLoggerJobService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<!-- ログ作成用レシーバークラス -->
<receiver
android:name="jp.profilepassport.android.logger.PPLoggerReceiver">
<intent-filter>
<!-- アプリ更新イベント -->
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
<intent-filter>
<!-- 起動イベント -->
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="jp.profilepassport.android.logger.action.PP_LOGGER_ACTION" />
<!-- 時間変更イベント -->
<action android:name="android.intent.action.TIME_SET" />
<!-- タイムゾーン変更イベント -->
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
</receiver>
<!-- ProfilePassportSdkのマニフェスト ここまで -->
}
在这里,NCMBFirebaseMessagingService扩展了FirebaseMessagingService。在PPSDK文档中,据说如果我们只在@onMessageReceived()中写入以下行,它将自动处理与PPSDK相关的通知(事实上它是这样做的):
但就在我实现它之后,PPSDK工作得很好,但之前运行的漂亮消息服务已经停止提供推送通知
我已尝试停止呼叫以启动PPSDK服务,但在禁用对PPSDK服务的启动呼叫后,Nifty仍然无法工作。我已经确保两个SDK的应用程序密钥、客户端令牌等都完全正常。还多次卸载和新安装。但这个问题还没有解决
这里有什么问题吗?这是因为常见的“通知通道id”吗?或者,在PPSDK开始工作后,服务器端是否发生了不可撤销的更改
public class CustomNiftyMessagingService extends NCMBFirebaseMessagingService {
public static final String FROM_PUSH = "FROM_PUSH";
private final int NOTIFICATION_ID = 1;
private final String TITLE = "title";
private final String MESSAGE = "message";
private final String PAYLOAD = "com.nifty.Data";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// PPSDKにRemoteMessageを渡して、処理呼び出し
PPSDKManager.onMessageReceived(getApplicationContext(), remoteMessage);
String title = remoteMessage.getData().get(TITLE);
String message = remoteMessage.getData().get(MESSAGE);
String payload = remoteMessage.getData().get(PAYLOAD);
// json文字列を変換
try {
Gson gson = new Gson();
CategoryInfo categoryInfo = gson.fromJson(payload, CategoryInfo.class);
NiftyPreference preference = new NiftyPreference(getApplicationContext());
preference.setCategoryInfo(categoryInfo);
} catch (Exception error) {
error.printStackTrace();
}
PendingIntent intent = createPendingIntent();
NotificationDirector director;
INotificationBuilder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder = new NotificationBuilderForOreo(this, getString(R.string.push_channel_id));
} else {
builder = new NotificationBuilder(this, getString(R.string.push_channel_id));
}
director = new NotificationDirector(builder);
director.constract(title, message, intent);
NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.getResult());
}
@Override
public void onMessageSent(String s) {
super.onMessageSent(s);
// PPSDK処理呼び出し
PPSDKManager.onMessageSent(s);
}
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
// PPSDK処理呼び出し
PPSDKManager.onDeletedMessages();
}
@Override
public void onSendError(String s, Exception e) {
super.onSendError(s, e);
// PPSDK処理呼び出し
PPSDKManager.onSendError(s, e);
}
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.d("PPSDK Sample", "############# onNewToken : " + s);
// PPSDK処理呼び出し
PPSDKManager.onTokenRefresh(getApplicationContext());
}
private PendingIntent createPendingIntent() {
// 表示したいActivityを指定する
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(FROM_PUSH, true);
return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
}
PPSDKManager.onMessageReceived(getApplicationContext(), remoteMessage);