0

我有一个 url 用于将服务器时间同步到我的应用程序,问题是如何做到这一点?任何人都可以向我解释在这里做什么,谢谢,我真的很感激。

这是 URL = http://server10.instaforex.com:2012/TimeService/TimeService.svc/CurrentTime

这是我的主要活动代码。

public class MainActivity extends Activity {

    Timer timeoutTimer;
    final Random myRandom = new Random();
    GenerateTask genTask = new GenerateTask();
    static String RAN_TEXT = "text";

    class GenerateTask extends TimerTask {
        boolean started = false;
        public void run() {
            if (started) {
                System.out.println("generating");
                final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);
                RAN_TEXT = "";

                for(int k=0;k<7;k++){
                    RAN_TEXT += myRandom.nextInt(10) + " ";
                }
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        textGenerateNumber.setText(RAN_TEXT);
                    }
                });
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button buttonGenerate = (Button)findViewById(R.id.generateme);

        buttonGenerate.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                System.out.println("click");
                if (!genTask.started) {
                    genTask.started=true;
                    timeoutTimer = new Timer();
                    timeoutTimer.scheduleAtFixedRate(genTask, 0, 30000);
                } else {
                    genTask.started=false;
                    timeoutTimer.cancel();
                }
            }
       });  
    }
}
4

2 回答 2

0

您提供的 URL 返回 XML 文件,里面没有任何类似时间的东西,您最好要求另一个 URL 或给您这个的人的解释:

<wsdl:definitions name="TimeService" targetNamespace="TimeService">
<wsdl:types>
<xsd:schema targetNamespace="TimeService/Imports">
<xsd:import schemaLocation="http://server10.instaforex.com:2012/TimeService/TimeService.svc?xsd=xsd0" namespace="TimeService"/>
<xsd:import schemaLocation="http://server10.instaforex.com:2012/TimeService/TimeService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema></wsdl:types><wsdl:message name="ITimeService_GetCurrentDateTime_InputMessage"><wsdl:part name="parameters" element="tns:GetCurrentDateTime"/>
</wsdl:message><wsdl:message name="ITimeService_GetCurrentDateTime_OutputMessage">
<wsdl:part name="parameters" element="tns:GetCurrentDateTimeResponse"/>
</wsdl:message><wsdl:portType name="ITimeService">
<wsdl:operation name="GetCurrentDateTime">
<wsdl:input wsaw:Action="TimeService/ITimeService/GetCurrentDateTime" message="tns:ITimeService_GetCurrentDateTime_InputMessage"/>
<wsdl:output wsaw:Action="TimeService/ITimeService/GetCurrentDateTimeResponse" message="tns:ITimeService_GetCurrentDateTime_OutputMessage"/>
</wsdl:operation></wsdl:portType><wsdl:binding name="BasicHttpBinding_ITimeService" type="tns:ITimeService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetCurrentDateTime">
<soap:operation soapAction="TimeService/ITimeService/GetCurrentDateTime" style="document"/>
<wsdl:input><soap:body use="literal"/>
</wsdl:input><wsdl:output><soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TimeService">
<wsdl:port name="BasicHttpBinding_ITimeService" binding="tns:BasicHttpBinding_ITimeService">
<soap:address location="http://server10.instaforex.com:2012/TimeService/TimeService.svc/basicHttpBinding"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
于 2013-03-23T02:01:51.003 回答
0

URL 是指向 WSDL 文件的链接,该文件描述了如何使用他们的 Web 服务来获取时间。您需要使用某种工具来生成 Web Service 以获取时间,例如 Apache CXF。但是,当您在谈论Android时,那太重了...

于 2013-03-23T03:58:31.740 回答