-1

我为我糟糕的英语和糟糕的java编程感到非常抱歉。请教我细节。非常感谢您的帮助。

现在我已经完成了我的应用程序。我想将此消息发送到mywebsite .com。

http:// mywebsite .com/web_service/counter/CSTrack2.aspxcli=focusgroup&cam=androidtest&1=W_S_UID&2=W_S_SC&3=W_S&5=W_S_DATE&7=www。我的网站 .com &8=www. 我的网站 .com% 2Ftc %2F&9=&10=W_S_IP&11=www。我的网站 .com &12=www. mywebsite .com%2F&13=&14=网站&15=W_S&16=W_S&17=W_S&19=windows&20=Win%207(x64)&21=1&22=9.0&23=1366x768&24=1&25=1&6=CRM%20%26%20%u6578%u4F4D%u884C %u92B7%u7684%u9818%u5C0E%u8005%20-%20MIGO%20CORP%20%u529F%u5178%u96C6%u5718%20&1375088741345

我需要用户的许可 INTERNET 吗?以及如何实现这一点?

4

2 回答 2

0

对于 android 中的任何网络通信,您必须在 Manifest 文件中声明 INTERNET 权限,而且所有网络通信都应在单独的线程上完成(使用异步任务),否则将引发运行时异常。

于 2013-07-30T04:42:12.750 回答
0
public class AsyncTaskExample extends AsyncTask<String, Void, Boolean>{
    private ProgressDialog progressDialog;
    private Activity activity;

    public AsyncTaskExample(Activity activity, ProgressDialog progress) {
        activity = activity;
        progressDialog = progress;
    }

    @Override
    protected void onPreExecute(){
        progressDialog.show();
    }   

    @Override
    protected Boolean doInBackground(String... params) {
//params is array of strings containing values which are passing while calling this AsyncTaskExample 
          int responseCode;
          String responseString;
          List<BasicNameValuePair> nameValuePairs = null;
          HttpParams httpParameters = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        int timeoutConnection = 20000;
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT) 
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 20000;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

        HttpClient httpclient = new DefaultHttpClient(httpParameters);

        HttpPost httpPost = new HttpPost("YOUR_URL");
        HttpResponse response;
        nameValuePairs = new ArrayList<BasicNameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("user", varTwo ));
            nameValuePairs.add(new BasicNameValuePair("password", varThree ));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            response = httpclient.execute(httpPost);
            responseCode = response.getStatusLine().getStatusCode();
            responseString = EntityUtils.toString(response.getEntity());

          return isSuccess; 
  }

    @Override
    protected void onPostExecute(Boolean isSuccess){ 
        try {
            progressDialog.dismiss();
        } catch (Exception e) {
            Log.e(TAG, "Error while closing dialog");
        }

    }

在代码中的某个位置调用 AsyncTaskExample,例如

AsyncTaskExample loginTask =  new AsyncTaskExample (this, progressDialog);
            task.execute(userName, password); 
// here userName, password are the params which should paass to your webservice, it will get in doInBackGroung by params variable as params[0], params[1]

you should also have internet permission in manifest file
于 2013-07-30T05:14:28.613 回答