Everythings正常工作,但是当我运行我的代码时,我会显示日志窗口:没有服务
好的但是; 我有一个错误,因为调试器说"标记"是的。为什么?
的onCreate;
Bundle bundle = new Bundle();
bundle.putString("ID", "MY ID NUMBER");
Intent sendintent = new Intent(SENT);
sendintent.putExtras(bundle);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sendintent, 0);
的onReceive;
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String tag = intent.getExtras().getString("ID");
Log.d("ID", tag); <<<NULL
switch (getResultCode()) {
case Activity.RESULT_OK:
Log.i("SmsSentReceiver", "SMS sent");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Log.i("SmsSentReceiver", "Generic failure");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Log.i("SmsSentReceiver", "No service");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Log.i("SmsSentReceiver", "Null PDU");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Log.i("SmsSentReceiver", "Radio off");
break;
}
}
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+xxxxxxx", null, "Hello", sentPI, null);
答案 0 :(得分:0)
尝试在PendingIntent.FLAG_UPDATE_CURRENT
的标记中使用0
代替getBroadcast()
。