我有一个扩展对话框的类,其中包含一个用于Pincode的Edittext,我已经注册了一个全局广播来接收SMS并解析它,然后在从消息中获取Pincode后,我发送另一个本地广播,其中包含以下代码
Intent broadcast = new Intent();
broadcast.setAction(SMS_RECEIVED);
intent.putExtra(SMS_PIN_CODE,msgBody.substring(msgBody.length() - SMS_PIN_CODE_LENGTH));
mContext.sendBroadcast(broadcast);
然后在我的对话框类中我创建了广播接收器来监听(SMS_RECEIVED)并将值放入UI中,如下所示
private BroadcastReceiver mPinCodeReceived = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(mContext, "I'm Here", Toast.LENGTH_SHORT).show();
if (mPincodeEdittext != null) {
String pinCode = intent
.getStringExtra(BillingConstatnts.SMS_PIN_CODE);
mPincodeEdittext.setText(pinCode);
}
}
};
我已在对话框类的onCreate方法中注册了此广播
LocalBroadcastManager.getInstance(mContext).registerReceiver(mPinCodeReceived,new IntentFilter(SMS_RECEIVED));
现在的问题是我的本地广播的onReceive方法没有被调用,所以有人可以告诉我这里有什么问题吗?
答案 0 :(得分:0)
好的,这就是我在消息传来时更新我的信息。我从我的服务中得到了一个广播,但这不应该是一个问题。
onResume(){
registerReceiver(broadcastBufferReceiver, new IntentFilter(BackgroundActivity.BROADCAST_BUFFER_SEND_CODE));
}
// set up broadcast receiver
private BroadcastReceiver broadcastBufferReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent bufferIntent) {
SendCode.this.LoadMessages(alarmNumber);
}
};