简体   繁体   English

获取来电号码?

[英]Get the incoming phone number?

i am developing a app that gets the incoming calling number . 我正在开发一个获取来电号码的应用程序。

this is my code through which i am trying to do this . 这是我正在尝试通过它的代码。

package com.example.callchecker;

import android.os.Bundle;
import android.app.Activity ;
import android.content.Context;
import android.telephony.*;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;

public class Main_Activity extends Activity {
    String number;
    TextView tv1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        tv1=(TextView) findViewById(R.id.textView1);

        TelephonyManager telephonymanager =
            (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        //register phone state
        PhoneStateListener callstatelestener = new PhoneStateListener() {
            public void OnCallStateChanged(int state , String incomingNumber) {
                number = incomingNumber;
                tv1.setText(number);
                // If phone ringing
                if(state==TelephonyManager.CALL_STATE_RINGING)
                {
                    Toast.makeText(getApplicationContext(), "Phone Is Riging",
                            Toast.LENGTH_LONG).show();
                }
            }
        };

        telephonymanager.listen(callstatelestener,
                PhoneStateListener.LISTEN_CALL_STATE);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main_layout, menu);
            return true;
    }
}

but this do not do any thing even when the call is make when i am in this app ... weather i have to make it working in background all the time ????? 但这即使在我使用此应用程序时拨打电话也不会做任何事情...天气我必须使其一直在后台工作?????? and if this is the right way to get the incoming number ??? 如果这是获取传入号码的正确方法?

您将在此广泛的教程中找到解决问题所需的所有答案: http : //www.vogella.com/articles/AndroidBroadcastReceiver/article.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 读取来电号码 - Reading the incoming phone number 在PCI调制解调器上打入电话时如何获取电话号码 - How to get phone number when have an incoming call on PCI modem 如何在来电和去电过程中获取电话号码? - How to get the phone number during an incoming and outgoing call? flutter中来电接入电话号码 - Access phone number of incoming calls in flutter 来自来电的电话号码无法正常工作 - phone number from incoming call not working android 对于 API &gt; 29 和 API &lt; 29 对于 Android 应用程序,我需要获取来电电话号码和该号码的通话记录的最低权限是多少? - What are the minimum permissions I need to get incoming phone number and call history for that number for API > 29 and API < 29 for Android app? Android Eclipse传入与传出SMS:电话号码格式? - Android Eclipse incoming vs outgoing SMS: Phone number format? 如何在某些特定来电号码上将手机状态更改为静音模式? - How to change state of phone to silent mode on some particular incoming number? 在 android 10 上以编程方式获取来电号码 - Get incoming call number programmatically on android 10 Android:如何检查BroadcastReceiver中联系电话中是否存在传入的SMS号码,且块号不存在 - Android : How to Check if incoming SMS number exist in contact phone in BroadcastReceiver and block is number not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM