[英]How to get the location without gps or internet and send it as sms to a preset number
[英]How to get GPS location and send in SMS android
我無法讓 GPS 工作。 我將它保存在一個名為 gps 的 SharedPreference 中,它將在 Toast 中打印為“ http://maps.google.com/?q= ” + lat + “ , ” + lon 當它通過 SMS 發送時就是這樣他們的接收者只需按下鏈接即可打開地圖。 但是當吐司上來時,它是空白的。 下面是我的代碼。
private void showLocation() {
LocationManager locationManager = (LocationManager)
getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
LocationListener loc_listener = new LocationListener() {
public void onLocationChanged(Location l) {}
public void onProviderEnabled(String p) {}
public void onProviderDisabled(String p) {}
public void onStatusChanged(String p, int status, Bundle extras) {}
};
locationManager
.requestLocationUpdates(bestProvider, 0, 0, loc_listener);
location = locationManager.getLastKnownLocation(bestProvider);
double lat, lon;
try {
lat = location.getLatitude();
lon = location.getLongitude();
} catch (NullPointerException e) {
lat = -1.0;
lon = -1.0;
}
prefs.setPreferenceString(getApplicationContext(),"gps" ,"http://maps.google.com/?q=" + lat + " , " + lon);
}
我正在嘗試制作這樣的應用程序,這里是運行良好的吐司代碼:
Handler handler3 = new Handler(Looper.getMainLooper());
handler3.post(new Runnable(){
@Override
public void run(){
Toast.makeText(context,"mensagem",Toast.LENGTH_LONG).show();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.