5

I have created an app, and my app have a feature relate to get number phone when have incomming phone, but i can not catch number phone, it is empty

My Service

public int onStartCommand(Intent intent, int flags, int startId) {
    TelephonyMgr = (TelephonyManager) getSystemService(getApplicationContext().TELEPHONY_SERVICE);
    TelephonyMgr.listen(new PhoneCallListener(),PhoneStateListener.LISTEN_CALL_STATE);
return START_STICKY;
}
private class PhoneCallListener extends PhoneStateListener {

    private boolean isPhoneCalling = false;
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i("NMC", "RINGING, number: " + incomingNumber);
        }
        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            Log.i("NMC", "RINGING, number: " + incomingNumber);
            isPhoneCalling = true;
        }
        if (TelephonyManager.CALL_STATE_IDLE == state) {
            Log.i("NMC", "IDLE number");

        }
    }

}

Manifest

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name="com.example.sev_user.smisscall.MyService">


    </service>

</application>

Log is displayed , but number phone is empty

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 1
    You're not the only person with the empty phonenumber problem ([see](http://stackoverflow.com/questions/33340628/android-telephonymanager-the-joys-of-phonestatelistener-and-incoming-numbers)). Does it works with a `BroadcastReveiver` like in [this answer](http://stackoverflow.com/a/13154533/3572108)? Also do you test it on an emulator? If so, try it on your real device. I hope something will help! – Bona Fide Jul 08 '16 at 08:40
  • 1
    Use BroadCastReceiver receiver Intent.action->than do something you want – Cgx Jul 08 '16 at 10:00

0 Answers0