我已经创建了一个应用程序,而且我的应用程序有一个功能与获取手机号码手机有关,但我无法接听号码手机,它是空的
我的服务
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");
}
}
}
清单
<?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>
显示日志,但号码电话为空