How to get gps location once for 5 mins android?

前端 未结 4 1830
独厮守ぢ
独厮守ぢ 2021-02-01 10:55

hi there can anybody give me a sample code for get location for every five minutes please i have tried and i can get location once by cliking on button, but i need it to be disp

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 11:15

    try like this:

     private Handler handler = new Handler(); 
    
     handler.postDelayed(runnable, 300000);
    
     private Runnable runnable = new Runnable() {   
        public void run() {
            if (location != null) {
    
                onLocationChanged(location);
            } else {
                System.out.println("Location not avilable");
            }
    
            handler.postDelayed(this, 300000);
        } 
    };
    

提交回复
热议问题