如何在API 29中获取来电号码?

时间:2019-07-29 01:40:26

标签: android

我想获取来电号码。我在我的课堂上增加了广播接收器,但是我无法从来电中得到任何号码。我无法通过舱单注册我的服务。如果有人知道该怎么做,请帮助我。`公共类CallBarring扩展了BroadcastReceiver {     公共字符串号;

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.intent.action.PHONE_STATE"))
    {
        // Fetch the number of incoming call
        //number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        System.out.println("Receiver start");
        Toast.makeText(context," Receiver start ", Toast.LENGTH_SHORT).show();
        TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        telephony.listen(new PhoneStateListener(){
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                super.onCallStateChanged(state, incomingNumber);


                Log.e("incomingNumber : ",incomingNumber);
            }
        } ,PhoneStateListener.LISTEN_CALL_STATE);`

0 个答案:

没有答案