0
通知に関する問題があります。私はFirebaseからのメッセージを聞くサービスをアプリに持っています。アプリがバックグラウンドであると、通知の動作が異なります
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// super.onMessageReceived(remoteMessage);
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
displayNotification(remoteMessage.getNotification().getBody());
}
private void displayNotification(String message) {
if (message.contains("upgrade")) {
upgradeClient(message);
}
}
private void upgradeClient(String message) {
final String appPackageName = getString(R.string.app_package);
String url;
try {
url = "market://details?id=" + appPackageName;
} catch (final Exception e) {
url = "https://play.google.com/store/apps/details?id=" + appPackageName;
}
//Open the app page in Google Play store:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText(message)
.setSmallIcon(R.drawable.ic_local_notification)
.setSound(notificationSound)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}
はアプリが前景化されると、通知はまさにそれが何をすべきん(この場合には、Playストアにユーザーを取る):ここに私のコードです。問題は、アプリがバックグラウンドである場合です。アプリがバックグラウンドである間に通知をタップすると、アプリが起動し、ユーザーはストアを再生することになりません。 upgradeClient()は呼び出されません。前もって感謝します!あなたが空であるかもしれないサービスに
文字列メッセージを取得している場合
あなたが怒っているかどうかを確認してください。 –
こんにちはjitesh mohite。あなたは正しいです、私はメッセージを得ていません。あなたのコメントを回答として投稿し、私はそれを受け入れます。仲間ありがとう –
が完了しました。それのためにありがとう –