需要帮助以显示呼叫者信息



我正在开发一个应用程序,该应用程序将显示来电的服务提供者(如Vodaphone等)信息。我用吐司来配合它。使用以下代码

      TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
                PhoneStateListener callStateListener = new PhoneStateListener() {
                public void onCallStateChanged(int state, String incomingNumber) 
                {
                        // TODO React to incoming call.
                        if(state==TelephonyManager.CALL_STATE_RINGING)
                        {
                                Toast.makeText(getApplicationContext(),finder.find(incomingNumber), Toast.LENGTH_LONG).show();
                        }
                }
                };
                telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE);

问题是吐司在很短的时间内可见。我想让它可见,直到用户没有接到电话(即直到电话响起,一旦收到吐司应该消失)。

我该怎么办。

我可以使用其他控件,如对话框等。

谢谢

处理程序线程中运行 toast,如下所示:

单击呼叫按钮时,请尝试以下操作:

            Button call = (Button) findViewById(R.id.call);
    call.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //call the user function to make call
        }
    });

并在您的类中添加此方法:

        private final Runnable mRunnable = new Runnable() {
    public void run() {
            Toast.makeText(getApplicationContext(),finder.find(incomingNumber), Toast.LENGTH_LONG).show();
        mHandler.postDelayed(mRunnable, 1000);
    }
};

并在单击"结束"按钮时或在用户接听呼叫后取消 Toast:

           Button end= (Button) findViewById(R.id.end);
    end.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //call the function to end the call if the other user dont receive
        }
    });

否则像你的函数一样使用:

     if(state==TelephonyManager.CALL_STATE_RINGING)
                    {
                            mHandler.postDelayed(mRunnable, 1000);
                    }

最新更新