ブラックベリーで場所を見つけるために次のコードを書きましたが、無効な場所のインスタンスを取得することがあります。場所を継続的に取得するには、場所リスナーにどの値を渡す必要がありますか?
package com.sims.sendlocation;
/**
*
* @author PramodKumarVishwakarma
*
*/
import java.util.Calendar;
import java.util.TimerTask;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import com.sims.commonmethods.Constants;
import com.sims.datahandler.GPRSHandler;
import com.sims.rms.RMSHandler;
public class LocationTimerTask extends TimerTask implements LocationListener {
private String locationStr;
private LocationProvider provider;
private String exception;
public void run()
{
try
{
Criteria criteria = new Criteria();
criteria.setCostAllowed(false);
//criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
provider = LocationProvider.getInstance(criteria);
provider.setLocationListener(this, -1, -1, -1);
}
catch (Exception e)
{
RMSHandler.addDataValues(Constants.CURRENT_LOCATION,"Provider Initialization: " + e.getMessage());
System.out.println("***********"+e);
}
if (checkTimeToSendMail())
startRequestThread();
}
public boolean cancel() {
return false;
}
private void startRequestThread()
{
final GPRSHandler gprs = new GPRSHandler();
Thread thread = new Thread() {
public void run() {
try {
sleep(Constants.MINUTE * Constants.LOC_THREAD_WAIT);
{
FindLocationReceiver location = new FindLocationReceiver();
location.sendOrderToServer(RMSHandler.getDataValues(Constants.IP_INFO)+ gprs.updateConnectionSuffix().trim());
}
} catch (InterruptedException e)
{
//Dialog.ask(Dialog.D_OK, "startRequestThread: " + e);
}
}
};
thread.start();
}
private boolean checkTimeToSendMail() {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR);
if (calendar.get(Calendar.AM_PM) == 0) {
if (hour >= Constants.MNG_TIME)
return true;
} else {
if (hour < Constants.EVNG_TIME)
return true;
}
return false;
}
public void locationUpdated(LocationProvider provider, Location location)
{
if (location.isValid())
{
locationStr = location.getQualifiedCoordinates().getLatitude()+ "-" + location.getQualifiedCoordinates().getLongitude();
RMSHandler.addDataValues(Constants.CURRENT_LOCATION, locationStr);
}
else
RMSHandler.addDataValues(Constants.CURRENT_LOCATION,"Not valid Location Provider");
}
public void providerStateChanged(LocationProvider provider, int newState)
{
}
}
有効な場所を取得できる場合もあれば、有効な場所を取得できない場合もあります。Listener パラメーター リストに渡す必要がある値はどれですか?