是否可以在 LocatioListener 类中打开文本到语音功能?
我正在尝试让一个 android 应用程序检测你移动了多远。我能够打开 GPS,并监控位置移动。我想让它说“你已经移动了 300 米”。将它放在 OnLocation 方法中会非常方便,但是当我尝试实例化 texttospeech 时它会抱怨?
这就是我正在尝试的:
public class Location implements LocationListener {
static TextToSpeech talk;
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
//这在下一行对我大喊大叫,不会让我使用'this'作为上下文??(也试过Location.this)
talk = new TextToSpeech(this, new extToSpeech.OnInitListener() {
public void onInit(int status) {
// TODO Auto-generated method stub
talk.setLanguage(Locale.UK);
Location aloc = new Location("aloc");
Location bloc = new Location("bloc");
aloc.setLatitude(alat);
aloc.setLongitude(alon);
bloc.setLatitude(blat);
bloc.setLongitude(blon);
float distance = aloc.distanceTo(bloc);
talk.speak("You Moved..", TextToSpeech.QUEUE_FLUSH, null);
}
});
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}