Skip to content

Commit

Permalink
修改README
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Apr 3, 2018
1 parent 4cdb4fa commit 326be40
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 104 deletions.
158 changes: 86 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Android APK 版本更新的下载和安装,适配7.0,8.0下载安装
2:安装APK

## 截图:
![](https://github.com/maning0303/MNUpdateAPK/raw/master/screenshots/002.png)
![](https://github.com/maning0303/MNUpdateAPK/raw/master/screenshots/002.jpg)
##### gif 比较慢
![](https://github.com/maning0303/MNUpdateAPK/raw/master/screenshots/001.gif)

Expand All @@ -28,7 +28,7 @@ Android APK 版本更新的下载和安装,适配7.0,8.0下载安装
#### 2.在Module目录下的build.gradle中添加依赖
``` gradle
dependencies {
compile 'com.github.maning0303:MNUpdateAPK:V1.1.7'
compile 'com.github.maning0303:MNUpdateAPK:V1.1.8'
}
```

Expand All @@ -47,87 +47,71 @@ Android APK 版本更新的下载和安装,适配7.0,8.0下载安装
```

### 2:代码使用
#### 构造函数(可以自定义下载路径):

``` java
/**
* 下载安装
*
* @param context 上下文
* @param httpUrl 下载地址
* @param saveName 保存的名字
* @param downloadCallBack 回调
*/
public InstallUtils(Context context, String httpUrl, String saveName, DownloadCallBack downloadCallBack) {
}


/**
* 下载安装
*
* @param context 上下文
* @param httpUrl 下载地址
* @param saveName 保存的名字
* @param savePath 保存路径
* @param downloadCallBack 回调
*/
public InstallUtils(Context context, String httpUrl, String saveName, String savePath, DownloadCallBack downloadCallBack) {
}

```

#### 本地下载安装:

``` java

//最新APK的下载地址
public static final String APK_URL = "http://download.fir.im/v2/app/install/5a52e936ca87a8600e0002f9?download_token=cd8662357947f151de92975b46082ba6&source=update";
//下载后的APK的命名
public static final String APK_NAME = "update";

new InstallUtils(context, APK_URL, APK_NAME, new InstallUtils.DownloadCallBack() {
@Override
public void onStart() {
Log.i(TAG, "InstallUtils---onStart");
}

@Override
public void onComplete(String path) {
Log.i(TAG, "InstallUtils---onComplete:" + path);

/**
* 安装APK工具类
* @param context 上下文
* @param filePath 文件路径
* @param callBack 安装界面成功调起的回调
*/
InstallUtils.installAPK(context, path, new InstallUtils.InstallCallBack() {
//下载APK
InstallUtils.with(this)
//必须-下载地址
.setApkUrl(Constants.APK_URL_03)
//非必须,默认update
.setApkName("update")
//非必须-下载保存的路径
.setApkPath(Constants.APK_SAVE_PATH)
//非必须-下载回调
.setCallBack(new InstallUtils.DownloadCallBack() {
@Override
public void onSuccess() {
Toast.makeText(context, "正在安装程序", Toast.LENGTH_SHORT).show();
public void onStart() {
//下载开始
}


@Override
public void onComplete(String path) {
//下载完成
/**
* 安装APK工具类
* @param context 上下文
* @param filePath 文件路径
* @param callBack 安装界面成功调起的回调
*/
InstallUtils.installAPK(context, path, new InstallUtils.InstallCallBack() {
@Override
public void onSuccess() {
Toast.makeText(context, "正在安装程序", Toast.LENGTH_SHORT).show();
}

@Override
public void onFail(Exception e) {
Toast.makeText(context, "安装失败:" + e.toString(), Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onLoading(long total, long current) {
//下载中
}

@Override
public void onFail(Exception e) {
Toast.makeText(context, "安装失败:" + e.toString(), Toast.LENGTH_SHORT).show();
//下载失败
}
});
}

@Override
public void onLoading(long total, long current) {
Log.i(TAG, "InstallUtils----onLoading:-----total:" + total + ",current:" + current);
}

@Override
public void onFail(Exception e) {
Log.i(TAG, "InstallUtils---onFail:" + e.getMessage());
}

}).downloadAPK();

@Override
public void cancle() {
//下载取消
}
})
//开始下载
.startDownload();


//取消下载
InstallUtils.cancleDownload();

//设置下载监听

//单独设置下载监听
InstallUtils.setDownloadCallBack(new InstallUtils.DownloadCallBack() {
@Override
public void onStart() {
Expand All @@ -148,7 +132,32 @@ Android APK 版本更新的下载和安装,适配7.0,8.0下载安装
public void onFail(Exception e) {

}

@Override
public void cancle() {

}
});


//安装APK
/**
* 安装APK工具类
* @param context 上下文
* @param filePath 文件路径
* @param callBack 安装界面成功调起的回调
*/
InstallUtils.installAPK(context, path, new InstallUtils.InstallCallBack() {
@Override
public void onSuccess() {
Toast.makeText(context, "正在安装程序", Toast.LENGTH_SHORT).show();
}

@Override
public void onFail(Exception e) {
Toast.makeText(context, "安装失败:" + e.toString(), Toast.LENGTH_SHORT).show();
}
});

```

Expand Down Expand Up @@ -191,6 +200,11 @@ Android APK 版本更新的下载和安装,适配7.0,8.0下载安装
```

## 版本记录:
##### 版本 V1.1.8:
1.可以取消下载
2.链式调用
3.版本改动大没需要重新设置代码

##### 版本 V1.1.7:
1.可以自定义下载路径
2.删除安装后kill自己代码
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/maning/mnupdateapk/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.maning.mnupdateapk;

import android.os.Environment;

/**
* <pre>
* author : maning
* e-mail : xxx@xx
* time : 2018/04/03
* desc :
* version: 1.0
* </pre>
*/
public class Constants {

public static final String APK_URL_01 = "http://download.fir.im/v2/app/install/56dd4bb7e75e2d27f2000046?download_token=e415c0fd1ac3b7abcb65ebc6603c59d9&source=update";
public static final String APK_URL_02 = "http://download.fir.im/v2/app/install/5a52e936ca87a8600e0002f9?download_token=cd8662357947f151de92975b46082ba6&source=update";
public static final String APK_URL_03 = "https://www.pgyer.com/apiv2/app/install?appKey=e6fcefdffc8c0ef2d7700e867f3b9685&_api_key=ae839fd4e088946dc307140042b97e17";

public static final String APK_SAVE_PATH = Environment.getExternalStorageDirectory() + "/MNUpdateAPK";

}
28 changes: 14 additions & 14 deletions app/src/main/java/com/maning/mnupdateapk/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
Expand All @@ -18,13 +16,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe

private static final String TAG = "InstallUtils";

// public static final String APK_URL = "http://download.fir.im/v2/app/install/56dd4bb7e75e2d27f2000046?download_token=e415c0fd1ac3b7abcb65ebc6603c59d9&source=update";
public static final String APK_URL = "http://download.fir.im/v2/app/install/5a52e936ca87a8600e0002f9?download_token=cd8662357947f151de92975b46082ba6&source=update";
// public static final String APK_URL = "https://www.pgyer.com/apiv2/app/install?appKey=e6fcefdffc8c0ef2d7700e867f3b9685&_api_key=ae839fd4e088946dc307140042b97e17";

public static final String APK_NAME = "update";
public static final String APK_SAVE_PATH = Environment.getExternalStorageDirectory() + "/MNUpdateAPK";


private Context context;

Expand Down Expand Up @@ -129,21 +120,30 @@ public void cancle() {
public void onClick(View v) {
switch (v.getId()){
case R.id.btnCancle:
InstallUtils.setCancle(true);
//取消下载
InstallUtils.cancleDownload();
btnDownload.setClickable(true);
btnDownload.setBackgroundResource(R.color.colorPrimary);
break;
case R.id.btnOther:
startActivity(new Intent(this, OtherActivity.class));
break;
case R.id.btnDownloadBrowser:
//通过浏览器去下载APK
InstallUtils.installAPKWithBrower(this, APK_URL);
InstallUtils.installAPKWithBrower(this, Constants.APK_URL_02);
break;
case R.id.btnDownload:
InstallUtils.with(this)
.apkUrl(APK_URL)
.apkName(APK_NAME)
//必须-下载地址
.setApkUrl(Constants.APK_URL_03)
//非必须,默认update
.setApkName("update")
//非必须-下载保存的路径
.setApkPath(Constants.APK_SAVE_PATH)
//非必须-下载回调
.setCallBack(downloadCallBack)
.downloadAPK();
//开始下载
.startDownload();
break;
}
}
Expand Down
Loading

0 comments on commit 326be40

Please sign in to comment.