- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
FirebasePluginInstanceIDService
package org.apache.cordova.firebase;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class FirebasePluginInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebasePlugin";
FirebasePlugin.getInstance().getInstanceId().addOnSuccessListener( MyActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String newToken = instanceIdResult.getToken();
Log.e("newToken", newToken);
}
});
}
package org.apache.cordova.firebase;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.app.Notification;
import android.text.TextUtils;
import android.content.ContentResolver;
import android.graphics.Color;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
import java.util.Random;
public class FirebasePluginMessagingService extends FirebaseMessagingService {
private static final String TAG = "FirebasePlugin";
private String getStringResource(String name) {
return this.getString(
this.getResources().getIdentifier( name, "string", this.getPackageName()));
}
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN", refreshedToken);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
boolean wasHandled =
FirebasePluginMessageReceiverManager.onMessageReceived(remoteMessage);
if (wasHandled) {
Log.d(TAG, "Message was handled by a registered receiver");
return;
}
String title = "";
String text = "";
String id = "";
String sound = "";
String lights = "";
Map<String, String> data = remoteMessage.getData();
if (remoteMessage.getNotification() != null) {
title = remoteMessage.getNotification().getTitle();
text = remoteMessage.getNotification().getBody();
id = remoteMessage.getMessageId();
} else if (data != null) {
title = data.get("title");
text = data.get("text");
id = data.get("id");
sound = data.get("sound");
lights = data.get("lights"); //String containing hex ARGB color, miliseconds on,
miliseconds off, example: '#FFFF00FF,1000,3000'
if (TextUtils.isEmpty(text)) {
text = data.get("body");
}
}
if (TextUtils.isEmpty(id)) {
Random rand = new Random();
int n = rand.nextInt(50) + 1;
id = Integer.toString(n);
}
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message id: " + id);
Log.d(TAG, "Notification Message Title: " + title);
Log.d(TAG, "Notification Message Body/Text: " + text);
Log.d(TAG, "Notification Message Sound: " + sound);
Log.d(TAG, "Notification Message Lights: " + lights);
// TODO: Add option to developer to configure if show notification when app on foreground
if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title) || (data != null && !data.isEmpty())) {
boolean showNotification = (FirebasePlugin.inBackground() ||
!FirebasePlugin.hasNotificationsCallback()) &&
(!TextUtils.isEmpty(text) ||
!TextUtils.isEmpty(title));
sendNotification(id, title, text, data, showNotification, sound, lights);
}
}
private void sendNotification(String id, String title, String messageBody, Map<String, String>
data, boolean showNotification, String sound, String lights) {
Bundle bundle = new Bundle();
for (String key : data.keySet()) {
bundle.putString(key, data.get(key));
}
if (showNotification) {
Intent intent = new Intent(this, OnNotificationOpenReceiver.class);
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, id.hashCode(), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
String channelId = this.getStringResource("default_notification_channel_id");
String channelName = this.getStringResource("default_notification_channel_name");
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
notificationBuilder
.setContentTitle(title)
.setContentText(messageBody)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX);
int resID = getResources().getIdentifier("notification_icon", "drawable",
getPackageName());
if (resID != 0) {
notificationBuilder.setSmallIcon(resID);
} else {
notificationBuilder.setSmallIcon(getApplicationInfo().icon);
}
if (sound != null) {
Log.d(TAG, "sound before path is: " + sound);
Uri soundPath = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
getPackageName() + "/raw/" + sound);
Log.d(TAG, "Parsed sound is: " + soundPath.toString());
notificationBuilder.setSound(soundPath);
} else {
Log.d(TAG, "Sound was null ");
}
if (lights != null) {
try {
String[] lightsComponents = lights.replaceAll("\\s", "").split(",");
if (lightsComponents.length == 3) {
int lightArgb = Color.parseColor(lightsComponents[0]);
int lightOnMs = Integer.parseInt(lightsComponents[1]);
int lightOffMs = Integer.parseInt(lightsComponents[2]);
notificationBuilder.setLights(lightArgb, lightOnMs, lightOffMs);
}
} catch (Exception e) {
}
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
int accentID = getResources().getIdentifier("accent", "color", getPackageName());
notificationBuilder.setColor(getResources().getColor(accentID, null));
}
Notification notification = notificationBuilder.build();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
int iconID = android.R.id.icon;
int notiID = getResources().getIdentifier("notification_big", "drawable",
getPackageName());
if (notification.contentView != null) {
notification.contentView.setImageViewResource(iconID, notiID);
}
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName,
NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(id.hashCode(), notification);
} else {
bundle.putBoolean("tap", false);
bundle.putString("title", title);
bundle.putString("body", messageBody);
FirebasePlugin.sendNotification(bundle, this.getApplicationContext());
}
}
}
最佳答案
因为它已贬值。修复非常简单,只需移动代码即可。
您可以在FirebaseMessagingService子类中将onTokenRefresh()的代码移动到onNewToken()
您可能需要通过cordova-plugin-firebasex使用cordova-plugin-firebase。
https://github.com/dpa99c/cordova-plugin-firebase#migrating-from-cordova-plugin-firebase。
另外寻找这个:
在https://firebase.google.com/support/release-notes/android#update_-_april_02_2019 96处,我找到了上一个工作版本,并相应地调整了project.properties,如下所示:
关于android - 我在FirebaseInstanceIdServices中收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59573928/
我正在创建一个聊天应用程序,根据教程我应该创建这个: Tutorial example 问题是现在这个函数 (FirebaseInstanceIdService) 不再存在,因此我不能使用它。有人会建
FirebaseInstanceIdService 在应用程序的开头启动,我希望它仅在身份验证后生成 token 。 我在 MainActivity 中尝试了这一行(它在身份验证后运行)但它没有用:
我遵循了互联网上的例子,并在此处和其他网站上复习了许多问题 我构建了我的应用程序,以便它处理 FCM 通知,但我仍然无法找出为什么 FirebaseInstanceIdService 没有被调用。 我
希望大家都知道这个类,用于在firebase通知 token 刷新时获取通知 token ,我们从这个类获取刷新的 token ,通过以下方法。 @Override public void onTok
我喜欢在 android studio 中重写我的代码,我是 android 开发的新手我的初始 MyFirebaseInstanceIDService 代码 @Override pu
正如标题所暗示的那样,如果我为 FCM 通知注册了一个 Android 应用程序并且该应用程序在后台运行或有一段时间没有启动并且 token 发生变化,onTokenRefresh()调用? 它会唤醒
我已经为云消息传递实现了 Firebase: https://firebase.google.com/docs/cloud-messaging/android/client#sample-regist
我尝试更新我的应用程序,但当应用程序应该生成 token 时,我显示错误。我的应用程序显示 token 未生成。 我的 firebase 代码如下: import android.util.Log;
因此,我正在尝试为我的应用程序使用 Firebase 云消息传递,但是当我尝试对其进行测试时,即使是示例代码也会向我抛出错误。 public class FirebaseIDService exten
我正在尝试将 FCM 通知添加到我的应用程序,但出于某种原因 FirebaseInstanceId.getInstance().getToken(); 正在返回 null。 因为我没有得到任何堆栈跟踪
public class LoginActivity extends AppCompatActivity { private static final int RC_SIGN_IN = 1;
这个问题已经有答案了: FirebaseInstanceIdService is deprecated (19 个回答) 已关闭 4 年前。 问题是,我想在我的聊天应用中使用 Firebase 云消息
我正在从 GCM 升级到 FCM。在 onTokenRefresh 之外获取 Firebase 设备 token 的正确方法是什么? 我正在尝试获取设备 token ,以便稍后可以在我的服务器上重新启
我想从客户端(android 应用程序)管理主题订阅。我目前正在 onCreate() Activity 中进行。我想知道正确的方法是在 InstanceIdService::onTokenRefre
当我调试时,这部分应用程序不执行,所以我不知道 token 何时刷新,即使我在调试前清除数据或卸载应用程序也是如此。 下图展示了我的代码。 有人能给我解释一下吗? 最佳答案 好的,让我们一步步来 首先
如果我使用教程中提供的代码,我会收到以下警告: Warning CS0618: 'FirebaseInstanceIdService' is obsolete: 'This class is obso
我不知道为什么每当我尝试创建我的应用程序构建时我都会收到此错误。我尝试了很多解决方案但我无法解决这个问题。我不知道是否有任何插件导致问题或者是否有任何我的代码或 firebase 或 firebase
我是一名优秀的程序员,十分优秀!