簡體   English   中英

如何在android studio中計算未接來電或拒絕來電

[英]How count missed call or reject call in android studio

在這里,我從我的應用程序撥打電話,我想計算未接來電或拒絕來電,我使用計數器(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);

    }
}

如果您可以調試並看到 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());
            }
        }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM