在Service中的后台线程中请求位置侦听器

时间:2019-06-05 08:01:13

标签: java android service

我需要在新的Thread()。start()中使用requestLocationUpdates(),因为我必须获取计时器间隔。

try {
            JSONObject response = new JSONObject(API.onRequest("session", new JSONObject().put("uuid", Settings.Secure.ANDROID_ID)));
            if (response.getBoolean("result")) {
                token = response.getString("token");
                int interval = response.getInt("interval");
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
            }
            Toast.makeText(LocationService.this, response.getString("detail"), Toast.LENGTH_LONG).show();
            //return;
        } catch (Exception ignored) {
        }

0 个答案:

没有答案