我没有收到使用4G网络的BroadcastReceiver的意图。我使用以下代码来接收短信发送结果的代码。我在2G蜂窝网络中获得了当前的结果,但没有获得4G
如果有任何机构有想法请回复。
谢谢。
registerReceiver(sendBroadcastReceiver, new IntentFilter("SENT"));
sendBroadcastReceiver = new BroadcastReceiver()
{
int result = getResultCode();
@Override
public void onReceive(Context context, Intent intent)
{
switch (result)
{
case Activity.RESULT_OK:
System.out.println("Received response");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
addFailedResultsInList("RESULT_ERROR_GENERIC_FAILURE");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
addFailedResultsInList("RESULT_ERROR_NO_SERVICE");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
addFailedResultsInList("RESULT_ERROR_NULL_PDU");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
addFailedResultsInList("RESULT_ERROR_RADIO_OFF");
break;
}
}
};
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
答案 0 :(得分:0)
除了创建BroadcastReceiver之外,您还需要为要获取的事件注册它。您可能想要学习本教程 http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html
当您想收到有关短信接收的通知时,您需要注册活动
android.provider.Telephony.SMS_RECEIVED
并请求权限 http://developer.android.com/reference/android/Manifest.permission.html#RECEIVE_SMS
答案 1 :(得分:0)
sendBroadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
result = getResultCode (); //<-------------------
switch (result)
{
case Activity.RESULT_OK:
System.out.println("Received response");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
addFailedResultsInList("RESULT_ERROR_GENERIC_FAILURE");
break;