gpt4 book ai didi

java - 如何处理fcm通知数据而不需要点击android中的通知弹出窗口

转载 作者:行者123 更新时间:2023-12-02 12:02:15 24 4
gpt4 key购买 nike

我使用了LocalBroadcastManager并在onmessagerecieved()中通过它传递数据

  if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());

Intent i=new Intent("com.taskty.tasktysupplierapp_FCM_MESSAGE");
String orderid=remoteMessage.getData().get("orderid");
String placeOfExecution=remoteMessage.getData().get("placeOfExecution");
i.putExtra("orderid",orderid);
i.putExtra("placeOfExecution",placeOfExecution);
LocalBroadcastManager lbm=LocalBroadcastManager.getInstance(this);
lbm.sendBroadcast(i);


if (/* Check if data needs to be processed by long running job */ true) {
// For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
scheduleJob();
} else {
// Handle message within 10 seconds
handleNow();
}
}

然后在启动器activity中将其调用为

private BroadcastReceiver mhandler=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

String orderid = intent.getStringExtra("orderid");
Toast.makeText(context, "order id is :"+orderid, Toast.LENGTH_SHORT).show();

}
};

@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mhandler);
}

@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mhandler,new IntentFilter("com.taskty.tasktysupplierapp_FCM_MESSAGE"));
}

并在setcontentview()之前在onCreate()中注册接收器

最佳答案

我通过覆盖以下方法找到了答案,它在所有情况下都有效,无论应用程序在后台还是前台,并且您可以从 Intent 获取数据

  @override
onhandleIntetn(Intent intent){}

关于java - 如何处理fcm通知数据而不需要点击android中的通知弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47159789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com