android - 仅在收到第一条消息后才允许第二条消息
问题描述
我正在尝试结合 2 Firebase Cloud 消息传递。我合并了 2 个项目,每个项目都有自己的 firebase 消息传递。我没有作为模块导入,而是创建了一个新包。任何帮助,将不胜感激。提前致谢。我尝试了“if else”、else 和许多其他组合。请帮忙,已经使用了一周并搜索许多论坛以找到结合 2 个 firebase 消息的答案。
//来自 MyFirebaseMessaging 类
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
//copied from second project
if(remoteMessage.getData() != null) {
//Log.d("EDMTDEV", remoteMessage.getNotification().getBody());
Map<String,String> data = remoteMessage.getData(); // Get data from notification :(
String customer = data.get("customer");
String lat = data.get("lat");
String lng=data.get("lng");
Intent intent = new Intent(getBaseContext(), CustomerCall.class);
intent.putExtra("lat", lat);
intent.putExtra("lng", lng);
intent.putExtra("customer", customer);
startActivity(intent);
}
// second message after the first one above "CustomerCall.class is active. this is a reply when a button is pressed on the above activity above has started, I DO NOT WANT IT TO START, only if a button is pressed on the above activity "CustomerCall.class" //
if(remoteMessage.getData() != null) {
Map<String,String> data = remoteMessage.getData();
String title = data.get("title");
final String message = data.get("message");
if (title.equals("Cancel")) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(MyFirebaseMessaging.this, message, Toast.LENGTH_SHORT).show();
}
});
LocalBroadcastManager.getInstance(MyFirebaseMessaging.this)
.sendBroadcast(new Intent("cancel_request"));
} else if (title.equals("Arrived")) {
showArrivedNotification(message);
} else if (title.equals("DropOff")) {
openRateActivity(message);
}
}
}
// 这是来自 CustomerCall.class
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_call);
btnCancel = (Button) findViewById(R.id.btnDecline);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!TextUtils.isEmpty(customerId))
cancelBooking(customerId);
finish();
}
});
}
private void cancelBooking(String customerId) {
Token2 token2 = new Token2(customerId);
Map<String,String> content = new HashMap<>();
content.put("title","Cancel");
content.put("message", "Driver has cancelled your request");
DataMessage2 dataMessage2 = new DataMessage2(token2.getToken(),content);
mFCMService.sendMessage(dataMessage2)
.enqueue(new Callback<FCMResponse2>() {
@Override
public void onResponse(Call<FCMResponse2> call, Response<FCMResponse2> response) {
if (response.body().success == 1) {
Toast.makeText(CustomerCall.this, "Cancelled", Toast.LENGTH_SHORT).show();
finish();
}
}
@Override
public void onFailure(Call<FCMResponse2> call, Throwable t) {
Log.d("EDMTLOG",t.getMessage());
}
});
}
解决方案
推荐阅读
- excel - 将公式转换为终极单元格引用 [IndexMatch、Offset、Indirect]
- javascript - 如何使用 yup 验证嵌套对象所需
- apache-nifi - Apache NiFi:将 SQL 行合并到 Json
- docker - Nginx Rverse Proxy to Tomcat(简单是......?否)
- postgresql - 带有 postgres-xl 的 zombodb:“zombodb.so:未定义符号:session_auth_is_superuser”
- scikit-learn - 如何在 sklearn-crfsuite 中取回不正确的 NER 预测
- database - 为什么下表是第二范式?
- c# - 如何通过 HttpResponseMessage 在 Web API、ASP.NET MVC 5 中返回文件
- powershell - 挣扎于 If 语句
- javascript - 变量末尾有询问点