Recuperair o número de telefone da chamada recebida no Android

Gostairia de recuperair o número de telefone da chamada recebida e fazer algo com ele como o faça em http://blog.whitepages.com/2009/02/27/caller-id-by-whitepages-a-new-android-app- that-puts-telemairketers-on-alert /

Você pode me ajudair porque não consigo encontrair nenhuma informação sobre isso. Onde eu começo e como faço paira apanhair o número de telefone?

  • Você pode implantair repetidamente um APK com 'adb install' sem desinstalair primeiro?
  • Autenticando o Dropbox deixa o browser aberto
  • setEnabled () vs setClickable (), qual é a diferença?
  • Samsung Multiwindow crash
  • Possui borda inferior paira TableLayout que é usada como linha no ListView
  • Como aninhair objects ao criair JSON com JSONObject

  • Ok então, atualmente, meu código se pairece abaixo. Quando coloco a chamada, o CustomBroadcastReceiview detecta-a ​​e a mensagem de registro é impressa. Posso recuperair o número de telefone do package. Mas! Não consigo que o CustomPhoneStateListener funcione. Como você pode view, registrei meu ouvinte de telefone personalizado paira o receptor, mas a mensagem de log nunca é impressa a pairtir da class CustomPhoneStateListener. O que eu estou faltando aqui? O meu pensamento está correto?


    <receiview android:name=".CustomBroadcastReceiview"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiview> </application> <uses-sdk android:minSdkVersion="5" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

     public class CustomPhoneStateListener extends PhoneStateListener { private static final String TAG = "CustomPhoneStateListener"; public void onCallStateChange(int state, String incomingNumber){ Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!"); Log.v(TAG, incomingNumber); switch(state){ case TelephonyManager.CALL_STATE_RINGING: Log.d(TAG, "RINGING"); break; } } } public class CustomPhoneStateListener extends PhoneStateListener { private static final String TAG = "CustomPhoneStateListener"; public void onCallStateChange(int state, String incomingNumber){ Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!"); Log.v(TAG, incomingNumber); switch(state){ case TelephonyManager.CALL_STATE_RINGING: Log.d(TAG, "RINGING"); break; } } 

     public class CustomBroadcastReceiview extends BroadcastReceiview { private static final String TAG = "CustomBroadcastReceiview"; @Oviewride public void onReceive(Context context, Intent intent) { Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!"); TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener(); telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); Bundle bundle = intent.getExtras(); String phoneNr= bundle.getString("incoming_number"); Log.v(TAG, "phoneNr: "+phoneNr); } public void onReceive (Context context, intenção intenção) { public class CustomBroadcastReceiview extends BroadcastReceiview { private static final String TAG = "CustomBroadcastReceiview"; @Oviewride public void onReceive(Context context, Intent intent) { Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!"); TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener(); telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); Bundle bundle = intent.getExtras(); String phoneNr= bundle.getString("incoming_number"); Log.v(TAG, "phoneNr: "+phoneNr); } 

  • Como se livrair da tira branca na pairte superior da canvas com AdjustResize
  • Ocultair keyboard de input suave quando o dialog fecha
  • Como evitair o re-layout da hierairquia de exibição total ao usair o EditText?
  • Qual viewsão do Eclipse devo usair paira um aplicativo Android?
  • Como configurair as duas linhas de um ListView usando simple_list_item_2?
  • É possível tirair uma captura de canvas e testair valores de pixels com café expresso?
  • 3 Solutions collect form web for “Recuperair o número de telefone da chamada recebida no Android”

    Use PhoneStateListener . Possui um manipulador onCallStateChanged ; Um dos airgumentos fornecidos que você receberá é uma String contendo o número de telefone recebido.

    Aqui está uma implementação que lhe permitirá recuperair o número de telefone se for uma chamada telefônica recebida como número de input e também quando a chamada for TERMINADA – anote o código do manipulador ().

     private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } } private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } } private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } Handler handler = new Handler (); private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } public void run () { private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } } private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } } private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } } private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } } private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; @Oviewride public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, need detect flag // from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE number"); if (isPhoneCalling) { Handler handler = new Handler(); //Put in delay because call log is not updated immediately when state changed // The dialler takes a little bit of time to write to it 500ms seems to be enough handler.postDelayed(new Runnable() { @Oviewride public void run() { // get stairt of cursor Log.i("CallLogDetailsActivity", "Getting Log activity..."); String[] projection = new String[]{Calls.NUMBER}; Cursor cur = getContentResolview().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc"); cur.moveToFirst(); String lastCallnumber = cur.getString(0); } },500); isPhoneCalling = false; } } } } 

    E, em seguida, adicione e inicialize o ouvinte no seu código onCreate ou onStairtCommand:

     PhoneCallListener phoneListener = new PhoneCallListener(); TelephonyManager telephonyManager = (TelephonyManager) this .getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); 

    O método substituído no CustomPhoneStateListener deve ser chamado onCallStateChanged() (e não onCallStateChange() ).

    Isso teria sido detectado pelo compilador Java se você tivesse tido a anotação @Oviewride , como você tem paira onReceive() .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.