我做了一个简单的应用程序来记录当前的地理位置并在移动屏幕上显示然后它在j2me模拟器中工作正常但是当应用程序安装在移动设备(诺基亚Asha 210)时,它安装并直接打开连接到蓝牙。它正在打开我无法理解的问题的蓝牙设置,所以我需要有关此问题的帮助..
这是我的整个代码......
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class LocationWithPolling extends MIDlet implements Runnable, CommandListener {
Form mainform;
Thread t;
LocationProvider lp;
Display display;
StringItem latitude;
StringItem longitude;
Command exitCommand=new Command("Exit",Command.OK,0);
protected void destroyApp(boolean arg0) {}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException
{
mainform=new Form("Location Polling");
latitude=new StringItem("Latitude:","N/A");
longitude=new StringItem("Longitude:","N/A");
Display.getDisplay(this).setCurrent(mainform);
mainform.append(latitude);
mainform.append(longitude);
mainform.addCommand(exitCommand);
mainform.setCommandListener(this);
t=new Thread(this);
t.start();
}
public void run()
{
try{
lp = LocationProvider.getInstance(null);
while(true)
{
Location loc=lp.getLocation(5000);
QualifiedCoordinates c=loc.getQualifiedCoordinates();
latitude.setText(String.valueOf(c.getLatitude()));
longitude.setText(String.valueOf(c.getLongitude()));
Thread.sleep(5000);
}
}catch(Exception e)
{
Alert alert =
new Alert("Error", "Could not retrieve location!", null, AlertType.ERROR);
display.setCurrent(alert);
}
}
public void providerStateChanged(LocationProvider provider, int newState) { }
public void commandAction(Command cmd, Displayable arg1)
{
if(cmd==exitCommand)
{
notifyDestroyed();
}
}
}
答案 0 :(得分:0)
Asha手机没有内置GPS,所以它试图连接到蓝牙GPS,你显然没有配对手机。这就是我认为它打开BT设置的原因。如果你有一个,它将连接到它。