English 中文(简体)
连接远程服务器的星座应用
原标题:Android Application that connects to remote server

我正试图在平台2.2 Froyo上建安安安。 该仪器应与一个远程服务器连接,从该服务器中取回数据,并用不同语言显示用户。

  • So my question - What technologies I need to learn so that I can build the above app.

注——我已经安装了“安”平台,并建造了像Hello这样的简单像。 我知道 Java。 我也在使用Eclipse。

感谢你的答复。 评注

页: 1 利用吉大港山区议定书连接网络的守则 页: 1

package in.androidbook.Networking;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity 
{
    ImageView img;
    /* This is for making asynchronous calls to ensure that connection to server will not return until data is received */

    private class BackgroundTask extends AsyncTask<String, Void, Bitmap>
    {
        protected Bitmap doInBackground(String...url)
        {
            Bitmap bitmap = DownloadImage(url[0]);
            return bitmap;
        }

        protected void onPostExecute(Bitmap bitmap)
        {
            ImageView img = (ImageView) findViewById(R.id.img);
            img.setImageBitmap(bitmap);         
        }
    }
    // Code for making HTTP connection
    private InputStream OpenHttpConnection(String urlString) throws IOException 
    {
        InputStream in = null;
        int response = -1;

        URL url = new URL(urlString);//We take an object of class URL
        URLConnection conn = url.openConnection(); //Create a connection object and open the connection

        if(!(conn instanceof HttpURLConnection)) throw new IOException("Not an Http connection");
        try
        {
            HttpURLConnection httpConn = (HttpURLConnection) conn; //httpConn object is assigned the value of conn. Typecasting is done to avoid conflict.
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            response = httpConn.getResponseCode();

            if(response == HttpURLConnection.HTTP_OK)
                in = httpConn.getInputStream();
        }
        catch (Exception ex)
        {
            throw new IOException("Error connecting");
        }
        return in;
    }   
        //------------------------------------------ OpenHttpConnection method completed----------------------------------------------------------//
    //----------------------------------------------------------------------------------------------------------------------------------------------------------------//
    //-------------------------------Method to download an image--------------------------------------------------------------------------------------//
    private Bitmap DownloadImage(String URL)
    {
        Bitmap bitmap = null;
        InputStream in = null;
        try
        {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in);
            in.close();
        }
        catch(IOException e1)
        {
            Toast.makeText(this, e1.getLocalizedMessage(), Toast.LENGTH_LONG).show();
            //Toast displays a short msg to user. this refers to current object.
            e1.printStackTrace();
        }
        return bitmap;
    }  


/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       Bitmap bitmap = DownloadImage("http://i.zdnet.com/blogs/3-29-androids.jpg");
        img = (ImageView) findViewById(R.id.img);
        img.setImageBitmap(bitmap);
    }
}
最佳回答

(根据评论): 当我们谈论客户时,我确认我的回答。 如果网站不是你,那么,如果检查网站如何/如果允许通过APIC进行某种通信,以及以何种形式(XML和JSON是最常用的)进行通信,则首先需要做。 有了这种信息,就应当非常容易。 借助谷歌地图或“推特”的“安”例子,你应当找到一些例子。

但这完全取决于你究竟是什么意思:你是否要求客户方面所需的技能——在服务器已经建成或由他人使用,或者服务器所需的技能方面?

在前一种情况下,我将建议与教育、科学和技术部的APIC和JSON联系。 考察一Pache HTTPGet、HTTPClient和HTTPResponse等和org.json(均列入Andre)。 如果你想与他们一起测试,就使用一些公共宣传器(因此,你不必担心服务器),例如谷歌地图标(在一定限度内简单而免费使用)。

在后一种情况下,I m与ColWinters :如果你知道java,也在那里使用,Tomcat作为服务器和基本服务器。 你在互联网上发现一些例子。

问题回答

研究这些技术,

Apache Tomcat - Java Server Pages (server processing) MySQL (storage of data)

and thats it. Also make sure to do the request in a seperate thread like an Async Task from an activity.

如果你知道java,我建议将服务器作为服务器上的服务器服务,该服务器读过我方ql或任何数据基和座标数据。 http://www.un.org。 因此。 “Serlets”,Httpclient,Json,如果你的用具是本土的,可以打电话。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签