public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("Received");
}
}
然后定义了一个Button (broadcast) 来监听注册:
broadcast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
IntentFilter filter = new IntentFilter();
filter.addAction(SMS_RECEIVED);
SMSReceiver receiver = new SMSReceiver();
registerReceiver(receiver, filter);
}
});
清单文件权限也给了:
但是为什么当我调试发短信时,广播的OnReceive方法一直没反应?