/Android_Study

android的基础学习

Primary LanguageJava

Android_Study

android的基础学习

###Dail

  • 说明:电话拨打

  • 实现方式:

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:"+number));
    startActivity(intent);

###Dialogs

  • 说明:各式对话框
  • 注意点:
    • AlertDialog 需要通过 AlertDialog.Builder 配置
    • 通过 builder.create() 创建
    • 通过 alertDialog.show() 显示

###Handler

  • 说明:Handler(用于沟通不同线程间的数据)

  • 实现方法:

    //The data must be transmitted by Message
    Message message = Message.obtain();
    message.obj = data;
    message.what = IS_FINISH;
    handler.sendMessage(message);

###Http

  • 说明:Android数据传输(Http、HttpClient方式)
  • 知识点:
    • HttpGet:
      1. 通过路径获取URL
      2. 通过使用url.openConnection()获取HttpURLConnection
      3. 通过conn.setConnectTimeout(Timeout)设置连接超时时间
      4. 连接时设置 conn.setRequestMethod(Method)"GET",即可实现GET方式访问
      5. 通过conn.getResponseCode()获得链接状态代码
      6. 如果responseCode==200表示服务器成功处理,则通过conn.getInputStream()获取输入流
      7. 最后通过InputStream获取传输的数据

    • HttpPost:
      1. 通过路径获得URL
      2. 通过使用url.openConnection()获取HttpURLConnection
      3. 通过conn.setConnectTimeout(Timeout)设置连接超时时间
      4. 连接时设置 conn.setRequestMethod(Method)"GET",即可实现GET方式访问
      5. 获取OutputStreamWriter(输出流),通过BufferedWriter向输出流中写入需要传递的参数
      6. 通过conn.getInputStream()获取输入流
      7. 最后通过InputStream获取传输的数据

    • HttpClientGet:
      1. 使用new DefaultHttpClient()获取HttpClient对象
      2. 使用new HttpGet(URL_PATH)获取HttpGet对象
      3. 执行client.execute(httpGet)即可获得HttpResponse对象
      4. 通过httpResponse.getEntity()获得HttpEntity对象
      5. 可以使用EntityUtils类的toXxxx(httpEntity)方法将HttpEntity类转化为对应来行的数据

    • HttpClientPost
      1. 使用new DefaultHttpClient()获取HttpClient对象
      2. 使用new HttpPost(URL_PATH)获取HttpPost对象
      3. 使用List<BasicNameValuePair>保存传输的参数
      4. list中插入的类型为BasicNameValuePair
      5. 使用new UrlEncodedFormEntity(list)list转化为HttpEntity对象
      6. 使用httpPost.setEntity(httpEntity)设置参数
      7. 通过httpResponse.getEntity()获得HttpEntity对象
      8. 可以使用EntityUtils类的toXxxx(httpEntity)方法将HttpEntity类转化为对应来行的数据