等待服务器响应getFromLocation android超时

时间:2015-04-09 10:35:38

标签: android progress-bar progressdialog google-geocoder

我有这段代码,应该在发送消息时创建进度对话框:

    public void launchRingDialog(ArrayList<String> numbers, String messageText) {

address = getAddress(mCurrentLocation.getLatitude(),
                    mCurrentLocation.getLongitude());

            final ArrayList<String> Numbers = numbers;
            final String poruka = address + messageText;
            final SmsManager sms = SmsManager.getDefault();

            final ArrayList<String> messages = sms.divideMessage(poruka.toString());

            final ProgressDialog ringProgressDialog = ProgressDialog.show(
                    getActivity(), "Please wait ...", "Sending message ...", true);

            final Handler uiCallback = new Handler(Looper
                    .getMainLooper());

            thread = new Thread() {
                @Override
                public void run() {
                    try {

                        for (String number : Numbers) {
                            if (messages.size() > 1) {
                                sms.sendMultipartTextMessage(number, null, messages, null,
                                        null);
                            } else {
                                sms.sendTextMessage(number, null, poruka, sentPI,
                                        deliveredPI);
                            }
                        }

                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }

                    uiCallback.post(new Runnable() {
                        @Override
                        public void run() {
                            ringProgressDialog.dismiss();
                        }
                    });

                }
            };

            thread.start();

        }

但我收到此错误消息:从服务器android.location.Geocoder.getFromLocation

响应waitng响应

请帮助,我尝试了一切,没有...问题是邮件已发送,但地址是空字符串,请帮助,谢谢。

这是getAddress

的代码
public String getAddress(double latitude, double longitude) {
        Geocoder geocoder = new Geocoder(getActivity(), Locale.ENGLISH);

        String address = "";

        try {
            List<Address> addresses = geocoder.getFromLocation(latitude,
                    longitude, 1);

            if (addresses != null) {
                Address returnedAddress = addresses.get(0);
                StringBuilder strReturnedAddress = new StringBuilder(
                        "Address:\n");
                for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                    strReturnedAddress
                            .append(returnedAddress.getAddressLine(i)).append(
                                    "\n");
                }
                address = strReturnedAddress.toString();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return address;
    }

0 个答案:

没有答案