android - Firebase Push Notofication 同时生成 apk
问题描述
在我的应用程序中,我需要一个已成功应用的推送通知功能。它还在模拟器中显示在应用程序上,但是我生成了签名的 apk 或构建了 apk,然后在我的应用程序中使用,然后我通过 firebase 使用云消息传递,然后它没有显示通知。为什么?
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
}
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
/**
* Persist token to third-party servers.
*
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
}
解决方案
推荐阅读
- excel - Find 在隐藏行的情况下产生错误
- python - Python try_decorator 重试 i2c 连接
- arrays - 使用 Google Sheets 将工作表中的数据行与 colA 中的序列号结合起来
- java - 在不同线程中清除缓冲区的正确方法
- wordpress - 在 wordpress 中保存元框选择值
- javascript - 使用while循环在数字和字符串之间进行等价
- reactjs - 使用 Firestore 和 Expo 时,ReadableNativeMap 无法转换为 java.lang.String
- r - 空分布相关问题(已编辑)
- elasticsearch - IllegalArgumentException:index.lifecycle.rollover_alias [logstash] 不指向索引
- ringcentral - 需要加数字线