开发者

Android: How to make function wait for another?

开发者 https://www.devze.com 2023-01-25 11:38 出处:网络
I want to send an sms message containing current location of user. How do I make the sending function w开发者_C百科ait till the location is calculated?Read about intents and you will find out. The tri

I want to send an sms message containing current location of user. How do I make the sending function w开发者_C百科ait till the location is calculated?


Read about intents and you will find out. The trick is you issue an intent when you get the location.


private class DeafLocationListener implements LocationListener {

    private final String provider;

    public DeafLocationListener(String provider) { this.provider = provider; }

    @Override public void onLocationChanged(Location location) { 
        Log.d(TAG, String.format("onLocationChanged triggered (%s)", provider));
        // SEND SMS HERE
    }
    @Override public void onProviderDisabled(String provider) { /*nop*/ }
    @Override public void onProviderEnabled(String provider) { /*nop*/ }
    @Override public void onStatusChanged(String provider, int status, Bundle extras) { /*nop*/ }

}

LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeGPS, minDistanceGPS, new DeafLocationListener("GPS"););
0

精彩评论

暂无评论...
验证码 换一张
取 消