Android中定义了一个接收短信的广播类,但是里面的OnReceive方法始终没有执行,求解
这个广播我就写了一句简单的输出语句:publicclassSMSReceiverextendsBroadcastReceiver{@Overridepublicvoido...
这个广播我就写了一句简单的输出语句:
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);
}
});
清单文件权限也给了:<uses-permission android:name="android.permission.RECEIVE_SMS"/>
但是为什么当我调试发短信时,广播的OnReceive方法一直没反应? 展开
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);
}
});
清单文件权限也给了:<uses-permission android:name="android.permission.RECEIVE_SMS"/>
但是为什么当我调试发短信时,广播的OnReceive方法一直没反应? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询