我希望在同一活动中收到新的SMS
。
为此,我尝试了以下代码。谁能告诉我我的代码有什么问题?
我的代码:
public BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("LOG", "message recived");
}
};
@Override
protected void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(mReceiver, intentFilter);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(this.mReceiver);
}
在Manifest
文件中添加此权限:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
提前谢谢。