在Android项目中使用OKHttp3怎么实现一个下载功能-创新互联

这篇文章给大家介绍在Android项目中使用OKHttp3怎么实现一个下载功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

成都创新互联公司专注于高平网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供高平营销型网站建设,高平网站制作、高平网页设计、高平网站官网定制、微信小程序开发服务,打造高平网络公司原创品牌,更为您提供高平网站排名全网营销落地服务。

app Module下的build.gradle,代码如下

apply plugin: 'com.android.application' 
 
android { 
  compileSdkVersion 24 
  buildToolsVersion "24.0.3" 
 
  defaultConfig { 
    applicationId "com.lanou3g.downdemo" 
    minSdkVersion 15 
    targetSdkVersion 24 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    //为了开启Java8 
    jackOptions{ 
      enabled true; 
    } 
  } 
  buildTypes { 
    release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
  } 
 
  //开启Java1.8 能够使用lambda表达式 
  compileOptions{ 
    sourceCompatibility JavaVersion.VERSION_1_8 
    targetCompatibility JavaVersion.VERSION_1_8 
  } 
} 
 
dependencies { 
  compile fileTree(dir: 'libs', include: ['*.jar']) 
  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
    exclude group: 'com.android.support', module: 'support-annotations' 
  }) 
  compile 'com.android.support:appcompat-v7:24.1.1' 
  testCompile 'junit:junit:4.12' 
 
  //OKHttp 
  compile 'com.squareup.okhttp3:okhttp:3.6.0' 
  //RxJava和RxAndroid 用来做线程切换的 
  compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 
  compile 'io.reactivex.rxjava2:rxjava:2.0.1' 
} 

分享标题:在Android项目中使用OKHttp3怎么实现一个下载功能-创新互联
本文链接:http://pwwzsj.com/article/dsdjcp.html