我想要一个BroadcastReciver
来电。
我已经在Stackoverflow上搜索了这个并且已经阅读了答案,但是当android设备开始振铃时它没有记录。这是我的代码 -
public class Mybrd extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
Log.i("LOG", "LOG ME");
}
}
清单:
<receiver android:name=".Mybrd">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
答案 0 :(得分:0)
检查您是否在清单文件中正确注册了接收器。如果它不在根包中,请使用完全限定的包名注册recevier。
答案 1 :(得分:0)
public void onReceive(Context context, Intent intent) {
String phoneState =intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
Log.i("LOG", "LOG ME");}}
尝试使用上面的代码。添加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>