在这里,我从我的应用程序拨打电话,我想计算错过或拒绝来电
我使用计数器(counterNoiseCalling)
来计算错过或拒绝来电,但Firebase计数器中的节点仍然总是等于0,我不知道为什么。
private class MyPhoneListener extends PhoneStateListener {
private boolean onCall = false;
String userNameCalling = UserDetails.username;
int counterNoisingCall = 0;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// phone ringing...
Toast.makeText(Call.this, incomingNumber + " calls you", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// one call exists that is dialing, active, or on hold
Toast.makeText(Call.this, "on call...", Toast.LENGTH_LONG).show();
if(!onCall) {
//because user answer the incoming call
Toast.makeText(Call.this, "The call is being answered", Toast.LENGTH_SHORT).show();
}else {
// reject call or missed call
Toast.makeText(Call.this, "Number Busy Or No Reply", Toast.LENGTH_SHORT).show();
counterNoisingCall++;
}
break;
case TelephonyManager.CALL_STATE_IDLE:
// in initialization of the class and at the end of phone call
// detect flag from CALL_STATE_OFFHOOK
if (onCall == true) {
Toast.makeText(Call.this, "restart app after call to Users List", Toast.LENGTH_LONG).show();
// restart our application to return to Our Contact
Intent restart = new Intent(Call.this , Users.class);
restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(restart);
onCall = false;
}
break;
default:
break;
}
Firebase childRef = mRootRef.child(userNameCalling);
childRef.setValue(counterNoisingCall);
}
}
答案 0 :(得分:0)
如果您可以调试并看到counterNoisingCall变量不为0,那么问题似乎与Firebase有关。
我猜这可能与安全规则有关。也许用户没有在Firebase节点上写入权限。
我会在setValue上放一个完整的监听器,看看命令是否成功完成。
试试这个。
Firebase childRef = mRootRef.child(userNameCalling);
childRef.setValue(counterNoisingCall).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Log.d("",task.getException().getMessage());
}
}
});