我尝试使用PHONE_STATE配置Broadcastreceiver。这是我的代码:
<receiver android:name=".IncomingCallReceiver"
android:enabled="true"
android:exported="true"
android:label="BootReceiver">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
班级:
public class IncomingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("TAG","ESTAMOS DENTRO!!");
MyPhoneStateListener phoneListener = new MyPhoneStateListener();
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
public class MyPhoneStateListener extends PhoneStateListener{
public void onCallStateChanged(int state, String incomingNumber){
switch (state){
case TelephonyManager.CALL_STATE_IDLE:
Log.d("DEBUG","IDLE");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("DEBUG","OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("DEBUG","RINGING: " + incomingNumber);
break;
default:
break;
}
}
}
}
这在我的仿真器(牛轧糖)中可以很好地工作,但是当我尝试在我的设备(7)中使用它时,却无法正常工作,我在logcat中什么也看不到。。
我尝试过优先还是没有优先。有导出/启用,没有导出。没事。
任何想法?
谢谢
答案 0 :(得分:0)
现在可以在其他设备上使用,这可能是我的设备出现的问题。 谢谢