zoukankan      html  css  js  c++  java
  • 安卓网络请求和图片加载

    1 网络如果是http  

      在res 下创建xml文件  再创建   network-security-config.xml    

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
    <base-config cleartextTrafficPermitted="true">
    <trust-anchors>
    <certificates src="system"/>
    <certificates src="user"/>
    </trust-anchors>
    </base-config>
    </network-security-config>

    在Androidmanifest

    //网络权限
    <uses-permission android:name="android.permission.INTERNET"/>
    <application

    android:networkSecurityConfig="@xml/network_security_config">
    </application>
    在build.gradle
    AS引用
    dependencies {

    implementation 'com.squareup.okhttp3:okhttp:3.12.0'
    implementation 'com.squareup.picasso:picasso:2.71828'

    }
    //数据加载
    //Activy
    //import okhttp3.Callback;
    //import okhttp3.OkHttpClient;
    //import okhttp3.Request;
    //import okhttp3.Call;
    //import okhttp3.Response;
    public  void addNework(){

    String url = "";
    OkHttpClient okHttpClient = new OkHttpClient();
    final Request request = new Request.Builder()
    .url(url)
    .get()//默认就是GET请求,可以不写
    .build();
    Call call = okHttpClient.newCall(request);

    call.enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {

    Log.v("Tag","eff"+e);

    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {

    Log.v("TAG", "onResponse: " + response.body().string());

    }
    });




    }

    //图片下载

    public void aaImageView(){

    Picasso.get().load("http://www.chaiqian88.com/d/file/sybanner/2018-10-23/1e184615665d4cd9a6bb82949d1614b0.png").into(imageView);
    // Picasso.with(this).load().info();

    //.onlyScaleDown()当调用了resize 方法重新设置图片尺寸的时候,调用onlyScaleDown 方法,只有当原始图片的尺寸大于我们指定的尺寸时,resize才起作用,
    //Picasso.get().load("http://www.chaiqian88.com/d/file/sybanner/2018-10-23/1e184615665d4cd9a6bb82949d1614b0.png").resize(400,200).onlyScaleDown().into(imageView);
    }
    一天一章
  • 相关阅读:
    spring jdbctemplate 集成duckdb docker 镜像
    GLIBCXX_3.4.x 问题解决
    spring jdbctemplate 集成duckdb
    spring-boot-starter-data-jdbc Cannot determine a dialect Please provide a Dialect
    kotlin 学习 三 maven 集成+java 互调用
    kotlin 学习 二 命令行模式运行
    kotlin 学习 一 环境搭建
    pt-ioprofile io 瓶颈分析工具
    zombodb 3000 alpha1发布
    openfeign+retronfit http 访问
  • 原文地址:https://www.cnblogs.com/hangman/p/10118518.html
Copyright © 2011-2022 走看看