简体   繁体   English

如何从WebService获取结果以显示在Android活动上?

[英]How can I get a result from a WebService to display on Android activity?

I have to create a Android application to make a Middleware because I have to question a big database. 我必须创建一个Android应用程序来制作中间件,因为我必须质疑一个大型数据库。

This Middleware must be program in J2EE. 该中间件必须是在J2EE中编写的程序。

To learn how to a middleware interacts with an Android app, I wrote a little function named "ping" : 为了学习中间件如何与Android应用程序交互,我编写了一个名为“ ping”的小函数:

@GET
@Path("/echo/{input}")
@Produces(MediaType.TEXT_PLAIN)
public String ping(@PathParam("input") String input) {
    return input;
}

This function use the variable named "input" in the path, and display the content of it on a web page. 该函数在路径中使用名为“ input”的变量,并将其内容显示在网页上。

My problem is, above function works, I tested it on a classical browser and the function returned the String named "input" on the webpage. 我的问题是,以上功能正常运行,我在经典浏览器上对其进行了测试,然后该功能在网页上返回了名为“ input”的字符串。 But now I want to question my Middleware with my Android App and display the content of "input" in my application activity. 但是,现在我想用我的Android应用程序质疑中间件,并在我的应用程序活动中显示“输入”的内容。

So how can I get this String in my app ? 那么如何在我的应用程序中获取此String?

You have to call the url used in the browser, from the android app. 您必须从android应用中调用浏览器中使用的网址。

From android you can call webservice using AsyncTask and HttpClient 从Android您可以使用AsyncTask和HttpClient调用Web服务

To call the url 呼叫网址

HttpClient httpClient = new DefaultHttpClient();
HttpGet postRequest = new HttpGet("http://"+ip+":8080/echo/hello");
ResponseHandler<String> handler = new BasicResponseHandler();           
String output= httpClient.execute(postRequest,handler);
httpClient.getConnectionManager().shutdown();

Check whether your service is at port number 8080! 检查您的服务是否在端口号8080上!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Java 类获取结果以显示在 Android 活动中? - How do I get the result from a Java class to display in an Android activity? 在Android中:如何将OnPostExecute()的结果发送到其他活动? - In Android: How can i send the result of from OnPostExecute() to other activity? 如何从适配器获取数据并在Android中的Activity中显示 - how can i get data from adapter and show in Activity in Android 如何从 android 片段中的活动中获取 MaterialSwitch id? - How can I get MaterialSwitch id from activity in fragment in android? 如何从另一个Web服务调用一个Web服务并返回结果 - How can i call one webservice from another webservice and return the result 如何在Android上使用Soap从Webservice发送和接收Hashmap - How can i send and receive Hashmap from Webservice with Soap on Android 如何从 onitemclick 获取数据并将其显示在另一个活动(Android Dev)上? - How to get data from onitemclick and display it on another activity (Android Dev)? 如何在按钮上显示随机活动单击在Android Studio中 - How Can I Display Random Activity On Button Click In Android Studio Android,获取第三次活动的结果 - Android, Get result from third activity 我如何从推送通知服务中获取消息并显示到消息活动中 - how can i get the message from my push notification service and display to my message activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM