final CountDownTimer gps_timer;
isLocationAvailable=false;
m_forsms=forsms;
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0f, this);
else
{
sendLocation_network(forsms);
return;
}
gps_timer = new CountDownTimer(15000,1000) {
int nn=0;
@Override
public void onTick(long arg0) {
nn++;
Toast.makeText(context, "gps counter :" + nn, Toast.LENGTH_SHORT).show();
if (isLocationAvailable) {
locationManager.removeUpdates(SendSMS.this);
gps_h.sendEmptyMessage(0);
}
}
@Override
public void onFinish() {
if (isLocationAvailable) {
locationManager.removeUpdates(SendSMS.this);
//Toast.makeText(context, "gps finish ok :" + nn, Toast.LENGTH_LONG).show();
}
else
{
//Toast.makeText(context, "GPS Fail :" + nn, Toast.LENGTH_LONG).show();
sendLocation_network(m_forsms);
}
}
};
gps_h=new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
gps_timer.cancel();
return true;
}
});
gps_timer.start();
http://stackoverflow.com/questionsのDUPのためにブロックされます/ 4958628/how-to-start-a-different-activity-with-some-delay-after-a-button-inおよび – stark