私は次のコードを持っていますが、これは不正な引数の例外によって登録されていないレシーバーを提供します
public class CheckServer extends IntentService
{
public String snumber;
public CheckServer()
{
super("CheckServer");
}
@Override
public void onCreate()
{
super.onCreate();
String DELIVERED = "SMS_DELIVERED";
DeliveryReceiver dReceiver = new DeliveryReceiver();
registerReceiver(dReceiver,new IntentFilter(DELIVERED));
}
@Override
public void onDestroy()
{
super.onDestroy();
DeliveryReceiver dReceiver = new DeliveryReceiver();
unregisterReceiver(dReceiver);
dReceiver = null;
}
@Override
protected void onHandleIntent(Intent intent)
{
try
{
serviceAction();
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
catch (JSONException e)
{
e.printStackTrace();
}
scheduleNextUpdate();
}
private void scheduleNextUpdate()
{
Intent intent = new Intent(this, this.getClass());
PendingIntent pendingIntent =
PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
long currentTimeMillis = System.currentTimeMillis();
long nextUpdateTimeMillis = currentTimeMillis + 1 * DateUtils.MINUTE_IN_MILLIS;
Time nextUpdateTime = new Time();
nextUpdateTime.set(nextUpdateTimeMillis);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent);
}
public void serviceAction() throws ClientProtocolException, IOException, URISyntaxException, JSONException
{
HttpResponse response = null;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://www.examplecom/sms/getsms"));
response = client.execute(request);
String result = convertStreamToString(response.getEntity().getContent());
String no,message;
JSONArray array = new JSONArray(result);
for (int i = 0; i < array.length(); i++)
{
JSONObject row = array.getJSONObject(i);
snumber = row.getString("sno");
no = row.getString("no");
message = row.getString("message");
sendSMS(no , message);
}
}
public static String convertStreamToString(InputStream inputStream) throws IOException
{
if (inputStream != null)
{
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try
{
Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"),1024);
int n;
while ((n = reader.read(buffer)) != -1)
{
writer.write(buffer, 0, n);
}
}
finally
{
inputStream.close();
}
return writer.toString();
}
else
{
return "";
}
}
public void sendSMS(String number,String message)
{
String DELIVERED = "SMS_DELIVERED";
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager smsM = SmsManager.getDefault();
smsM.sendTextMessage(number, null, message, null, deliveredPI);
}
public class DeliveryReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent arg1)
{
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",Toast.LENGTH_SHORT).show();
try
{
updateSMSstatus(snumber);
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",Toast.LENGTH_SHORT).show();
break;
}
}
public void updateSMSstatus(String sno) throws URISyntaxException, ClientProtocolException, IOException
{
HttpResponse response = null;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://www.example.com/sms/updatesmsstatus?uname=someone&sno="+sno));
response = client.execute(request);
}
}
問題は、onCreate()メソッドに登録しても、レジスタが受信されないというエラーが発生することです。問題は何でしょうか。