Explorar o código

add download files

yanyi %!s(int64=6) %!d(string=hai) anos
pai
achega
38a98ee3e7

+ 3 - 3
app/src/main/AndroidManifest.xml

@@ -18,13 +18,13 @@
         android:theme="@style/AppTheme"
         tools:ignore="GoogleAppIndexingWarning">
         <activity android:name=".MainActivity">
-
-        </activity>
-        <activity android:name=".DownloadActivity">
             <intent-filter>
                 <category android:name="android.intent.category.LAUNCHER" />
                 <action android:name="android.intent.action.MAIN" />
             </intent-filter>
+        </activity>
+        <activity android:name=".DownloadActivity">
+
         </activity>
         <!-- 定义FileProvider -->
         <provider

+ 2 - 1
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 
 import com.mylove.loglib.JLog;
+import com.mylove.okhttp.download.UpdateUtil;
 import com.mylove.okhttp.listener.OnOkHttpListener;
 import com.yanyi.permissionlib.PermissionHelper;
 import com.yanyi.permissionlib.PermissionType;
@@ -94,7 +95,7 @@ public class MainActivity extends AppCompatActivity {
 //                JLog.e(t.getMessage());
 //            }
 //        });
-        UpdateUtil updateUtil = new UpdateUtil(this, url)
+        UpdateUtil updateUtil = new UpdateUtil(this, this, url)
                 .setIcon(R.mipmap.ic_launcher)
                 .setMessage("更新")
                 .setTitle("更新测试")

+ 1 - 1
app/src/main/res/xml/file_provider.xml

@@ -11,7 +11,7 @@
     <!--3、对应外部内存卡根目录:Environment.getExternalStorageDirectory()-->
     <external-path
         name="ext_root"
-        path="dectector/" />
+        path="com.mylove.okhttp/" />
     <!--4、对应外部内存卡根目录下的APP公共目录:Context.getExternalFileDir(String)-->
     <external-files-path
         name="ext_pub"

+ 0 - 261
okhttplib/src/main/java/com/mylove/okhttp/UpdateUtil.java

@@ -1,261 +0,0 @@
-package com.mylove.okhttp;
-
-import android.app.Activity;
-import android.app.ProgressDialog;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Build;
-import android.support.annotation.DrawableRes;
-import android.support.v4.content.FileProvider;
-import android.support.v7.app.AlertDialog;
-
-import com.mylove.okhttp.listener.OnDownloadCallBack;
-
-import java.io.File;
-
-/**
- * @author BenYanYi
- * @date 2018/11/20 10:23
- * @email ben@yanyi.red
- * @overview
- */
-public class UpdateUtil {
-    private Activity mActivity;
-
-    private String downloadUrl = "";//app下载地址
-    private String title = "升级";
-    private String message = "发现新的安装包";
-    private boolean isLimit = false;//是否可以关闭
-
-    private boolean isShowNotice = false;//是否显示通知栏
-
-    private int icon;
-
-    private NotificationUtil notificationUtil;
-
-    private Class<?> aClass;
-
-    private ProgressDialog progressDialog;
-
-    private boolean isInstallApk = false;
-    private OnDownloadCallBack onDownloadCallBack;
-
-    private String filePath;
-
-    public UpdateUtil(Activity mActivity, String downloadUrl) {
-        this.mActivity = mActivity;
-        setDownloadUrl(downloadUrl);
-    }
-
-    public UpdateUtil setDownloadUrl(String downloadUrl) {
-        if (FormatUtil.isEmpty(downloadUrl)) {
-            throw new NullPointerException("");
-        }
-        this.downloadUrl = downloadUrl;
-        return this;
-    }
-
-    /**
-     * 设置弹窗标题
-     */
-    public UpdateUtil setTitle(String title) {
-        if (FormatUtil.isNotEmpty(title)) {
-            this.title = title;
-        }
-        return this;
-    }
-
-    /**
-     * 设置弹窗内容
-     */
-    public UpdateUtil setMessage(String message) {
-        if (FormatUtil.isNotEmpty(message)) {
-            this.message = message;
-        }
-        return this;
-    }
-
-    /**
-     * 是否需要强制下载
-     */
-    public UpdateUtil setLimit(boolean limit) {
-        isLimit = limit;
-        return this;
-    }
-
-    /**
-     * 是否显示通知弹窗
-     */
-    public UpdateUtil setShowNotice(boolean showNotice) {
-        isShowNotice = showNotice;
-        return this;
-    }
-
-    /**
-     * 通知弹窗跳转页面
-     *
-     * @param aClass
-     */
-    public UpdateUtil setStartClass(Class<?> aClass) {
-        this.aClass = aClass;
-        return this;
-    }
-
-    /**
-     * 设置图标
-     */
-    public UpdateUtil setIcon(@DrawableRes int icon) {
-        this.icon = icon;
-        return this;
-    }
-
-    /**
-     * 是否需要安装
-     */
-    public UpdateUtil setInstallApk(boolean installApk) {
-        isInstallApk = installApk;
-        return this;
-    }
-
-    /**
-     * 下载监听
-     */
-    public UpdateUtil setDownloadCallBack(OnDownloadCallBack downloadCallBack) {
-        this.onDownloadCallBack = downloadCallBack;
-        return this;
-    }
-
-    /**
-     * 存储目录
-     */
-    public UpdateUtil setFilePath(String filePath) {
-        this.filePath = filePath;
-        return this;
-    }
-
-    /**
-     * 升级
-     */
-    public void request() {
-        if (FormatUtil.isEmpty(title)) {
-            title = "提示";
-        }
-        if (FormatUtil.isEmpty(message)) {
-            message = "是否下载";
-        }
-        if (isShowNotice) {
-            notificationUtil = new NotificationUtil(mActivity, icon, title);
-            if (aClass != null) {
-                notificationUtil.setClass(aClass);
-            }
-        }
-        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
-        if (icon != 0) {
-            builder.setIcon(icon);
-        }
-        builder.setTitle(title);
-        builder.setMessage(message);
-        builder.setPositiveButton("立即更新", new DialogInterface.OnClickListener() {
-            @Override
-            public void onClick(DialogInterface dialog, int which) {
-                dialog.dismiss();
-                progressDialog();
-            }
-        });
-        if (!isLimit) {
-            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialog, int which) {
-                    dialog.dismiss();
-                }
-            });
-        }
-        builder.setCancelable(!isLimit);
-        builder.show();
-
-    }
-
-    private void progressDialog() {
-        progressDialog = new ProgressDialog(mActivity);
-        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
-        progressDialog.setTitle(title);
-        progressDialog.setMessage("正在下载");
-        progressDialog.setMax(100);
-        progressDialog.setProgress(0);
-        // 设置ProgressDialog 的进度条是否不明确
-        progressDialog.setIndeterminate(false);
-        progressDialog.setCancelable(false);
-        if (icon != 0)
-            progressDialog.setIcon(icon);
-        progressDialog.show();
-        notificationUtil.showNotification(1020);
-        download();
-    }
-
-    private void download() {
-        if (FormatUtil.isEmpty(filePath)) {
-            filePath = mActivity.getPackageName();
-        }
-
-        OkHttpUtil.getInstance(mActivity).downloadFile(downloadUrl).downloads(filePath, new DownloadObserver() {
-            @Override
-            public void onNext(DownloadBean downloadBean) {
-                if (downloadBean == null) {
-                    if (onDownloadCallBack != null) {
-                        onDownloadCallBack.onFailure(new Throwable("下载失败"));
-                    }
-                } else if (downloadBean.status == 0) {
-                    if (notificationUtil != null && isShowNotice) {
-                        notificationUtil.updateProgressText(1020, downloadBean.progress, "已下载" + downloadBean.progress + "%");
-                    }
-                    progressDialog.setProgress(downloadBean.progress);
-                    progressDialog.setMax(100);
-                    progressDialog.setMessage("已下载" + downloadBean.progress + "%");
-                    if (onDownloadCallBack != null) {
-                        onDownloadCallBack.onDownloading(downloadBean.progress);
-                    }
-                } else if (downloadBean.status == 1) {
-                    d.dispose();
-                    progressDialog.dismiss();
-                    notificationUtil.cancel(1020);
-                    if (isInstallApk && FileUtil.ifUrl(downloadBean.filePath, ".apk")) {
-                        installApk(new File(downloadBean.filePath));
-                    }
-                }
-            }
-
-            @Override
-            public void onError(Throwable e) {
-                super.onError(e);
-                if (onDownloadCallBack != null) {
-                    onDownloadCallBack.onFailure(e);
-                }
-            }
-        });
-    }
-
-    /**
-     * 安装下载完成的安装包
-     *
-     * @param file
-     */
-    private void installApk(File file) {
-        //判读版本是否在7.0以上
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            //在AndroidManifest中的android:authorities值
-            LogHelper.a(file.getAbsolutePath());
-            Uri apkUri = FileProvider.getUriForFile(mActivity, mActivity.getPackageName() + ".fileProvider", file);
-            Intent install = new Intent(Intent.ACTION_VIEW);
-            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-            install.setDataAndType(apkUri, "application/vnd.android.package-archive");
-            mActivity.startActivity(install);
-        } else {
-            Intent install = new Intent(Intent.ACTION_VIEW);
-            install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
-            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            mActivity.startActivity(install);
-        }
-    }
-}

+ 2 - 3
okhttplib/src/main/java/com/mylove/okhttp/download/DownloadManager.java

@@ -2,7 +2,6 @@ package com.mylove.okhttp.download;
 
 import android.content.Context;
 
-import com.mylove.okhttp.FileUtil;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -119,7 +118,7 @@ public class DownloadManager {
 
     private DownloadInfo getRealFileName(DownloadInfo downloadInfo) throws Exception {
         String fileName = downloadInfo.getFileName();
-        String savePath = FileUtil.isExistDir(mContext.getPackageName() + "/download");
+        String savePath = FileUtil.isExistDir(mContext.getPackageName());
         long downloadLength = 0, contentLength = downloadInfo.getTotal();
         File file = new File(savePath, fileName);
         if (file.exists()) {
@@ -172,7 +171,7 @@ public class DownloadManager {
             Call call = mClient.newCall(request);
             downCalls.put(url, call);//把这个添加到call里,方便取消
             Response response = call.execute();
-            String savePath = FileUtil.isExistDir(mContext.getPackageName() + "/download");
+            String savePath = FileUtil.isExistDir(mContext.getPackageName());
             File file = new File(savePath, downloadInfo.getFileName());
             InputStream is = null;
             FileOutputStream fileOutputStream = null;

+ 89 - 0
okhttplib/src/main/java/com/mylove/okhttp/download/FileUtil.java

@@ -0,0 +1,89 @@
+package com.mylove.okhttp.download;
+
+import android.graphics.Bitmap;
+import android.os.Environment;
+import android.support.annotation.NonNull;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @author myLove
+ */
+
+class FileUtil {
+    /**
+     * @param saveDir
+     * @return
+     * @throws IOException 判断下载目录是否存在
+     */
+    static String isExistDir(String saveDir) throws IOException {
+        // 下载位置
+        File downloadFile = new File(Environment.getExternalStorageDirectory(), saveDir);
+        if (!downloadFile.mkdirs()) {
+            downloadFile.createNewFile();
+        }
+        String savePath = downloadFile.getAbsolutePath();
+        return savePath;
+    }
+
+    /**
+     * 图片保存
+     */
+    static String saveImage(Bitmap bitmap, String path) {
+        File file = new File(path);
+        try {
+            if (!file.exists()) {
+                file.createNewFile();
+            }
+            FileOutputStream fos = new FileOutputStream(file);
+            String substring = path.substring(path.length() - 3, path.length());
+            if (substring.equals("png")) {
+                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
+            } else {
+                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
+            }
+            fos.flush();
+            fos.close();
+        } catch (Exception e) {
+            e.fillInStackTrace();
+        }
+        return path;
+    }
+
+    static String getSDPath() {
+        File sdDir = null;
+        boolean sdCardExist = Environment.getExternalStorageState()
+                .equals(Environment.MEDIA_MOUNTED); //判断sd卡是否存在
+        if (sdCardExist) {//判断sd卡是否存在
+            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
+        }
+        return sdDir.toString();
+    }
+
+    /**
+     * @param url
+     * @return 从下载连接中解析出文件名
+     */
+    @NonNull
+    static String getNameFromUrl(String url) {
+        return url.substring(url.lastIndexOf("/") + 1);
+    }
+
+    /**
+     * 判断当前url下载的文件是否为自己所需的
+     *
+     * @param url
+     * @param condition 判断条件
+     * @return
+     */
+    static boolean ifUrl(String url, String condition) {
+        String str = url.substring(url.lastIndexOf("."));
+        if (FormatUtil.isNotEmpty(str)) {
+            return str.equals(condition);
+        } else {
+            return false;
+        }
+    }
+}

+ 37 - 0
okhttplib/src/main/java/com/mylove/okhttp/download/FormatUtil.java

@@ -0,0 +1,37 @@
+package com.mylove.okhttp.download;
+
+import java.util.Map;
+
+/**
+ * 字符串工具类
+ */
+class FormatUtil {
+
+    /**
+     * 判断字符串是否为空
+     *
+     * @param str
+     * @return true 不为空, false 为空
+     */
+    static boolean isNotEmpty(String str) {
+        return str != null && !"null".equals(str) && str.trim().length() != 0;
+    }
+
+    /**
+     * 判断字符串是否为空
+     *
+     * @param str
+     * @return true 为空,false 不为空
+     */
+    static boolean isEmpty(String str) {
+        return str == null || "null".equals(str) || str.trim().length() == 0;
+    }
+
+    /**
+     * 判断MAP是否为空
+     */
+    static <K, V> boolean isMapNotEmpty(Map<K, V> map) {
+        return map != null && map.size() > 0;
+    }
+
+}

+ 3 - 1
okhttplib/src/main/java/com/mylove/okhttp/NotificationUtil.java → okhttplib/src/main/java/com/mylove/okhttp/download/NotificationUtil.java

@@ -1,4 +1,4 @@
-package com.mylove.okhttp;
+package com.mylove.okhttp.download;
 
 import android.app.Activity;
 import android.app.Notification;
@@ -10,6 +10,8 @@ import android.content.Intent;
 import android.graphics.Color;
 import android.widget.RemoteViews;
 
+import com.mylove.okhttp.R;
+
 import java.util.HashMap;
 import java.util.Map;
 

+ 35 - 0
okhttplib/src/main/java/com/mylove/okhttp/download/UpdateObserver.java

@@ -0,0 +1,35 @@
+package com.mylove.okhttp.download;
+
+import com.mylove.okhttp.DownloadBean;
+import com.mylove.okhttp.DownloadObserver;
+import com.mylove.okhttp.LogHelper;
+
+import io.reactivex.Observer;
+import io.reactivex.disposables.Disposable;
+
+/**
+ * @author BenYanYi
+ * @date 2018/12/03 10:18
+ * @email ben@yanyi.red
+ * @overview
+ */
+public abstract class UpdateObserver extends DownloadObserver implements Observer<DownloadBean> {
+    @Override
+    public void onSubscribe(Disposable d) {
+        super.onSubscribe(d);
+    }
+
+    @Override
+    public void onComplete() {
+        super.onComplete();
+    }
+
+    @Override
+    public void onError(Throwable e) {
+        super.onError(e);
+        LogHelper.e("UpdateUtil--->>" + e.getMessage());
+    }
+
+    protected void onDialogDismiss() {
+    }
+}

+ 344 - 0
okhttplib/src/main/java/com/mylove/okhttp/download/UpdateUtil.java

@@ -0,0 +1,344 @@
+package com.mylove.okhttp.download;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Build;
+import android.support.annotation.DrawableRes;
+import android.support.v4.content.FileProvider;
+import android.support.v7.app.AlertDialog;
+import android.widget.ProgressBar;
+
+import com.mylove.okhttp.LogHelper;
+
+import java.io.File;
+
+/**
+ * @author BenYanYi
+ * @date 2018/11/20 10:23
+ * @email ben@yanyi.red
+ * @overview
+ */
+public class UpdateUtil {
+    private Activity mActivity;
+    private Context mContext;
+
+    private String downloadUrl = "";//app下载地址
+    private String title = "升级";
+    private String message = "发现新的安装包";
+    private static boolean isLimit = false;//是否可以关闭
+
+    private boolean isShowNotice = false;//是否显示通知栏
+
+    private int icon;
+
+    private NotificationUtil notificationUtil;
+
+    private Class<?> aClass;
+
+    private ProgressDialog progressDialog;
+    private ProgressBar progressBar;
+
+    private static boolean isInstallApk = false;
+    private UpdateObserver updateObserver;
+
+    private String filePath;
+
+    private static final int INSTALL_APK = 0x1020;
+
+    public UpdateUtil(Context context, Activity mActivity, String downloadUrl) {
+        this.mActivity = mActivity;
+        this.mContext = context;
+        setDownloadUrl(downloadUrl);
+    }
+
+    public UpdateUtil setDownloadUrl(String downloadUrl) {
+        if (FormatUtil.isEmpty(downloadUrl)) {
+            throw new NullPointerException("");
+        }
+        this.downloadUrl = downloadUrl;
+        return this;
+    }
+
+    /**
+     * 设置弹窗标题
+     */
+    public UpdateUtil setTitle(String title) {
+        if (FormatUtil.isNotEmpty(title)) {
+            this.title = title;
+        }
+        return this;
+    }
+
+    /**
+     * 设置弹窗内容
+     */
+    public UpdateUtil setMessage(String message) {
+        if (FormatUtil.isNotEmpty(message)) {
+            this.message = message;
+        }
+        return this;
+    }
+
+    /**
+     * 是否需要强制下载
+     */
+    public UpdateUtil setLimit(boolean limit) {
+        isLimit = limit;
+        return this;
+    }
+
+    /**
+     * 是否显示通知弹窗
+     */
+    public UpdateUtil setShowNotice(boolean showNotice) {
+        isShowNotice = showNotice;
+        return this;
+    }
+
+    /**
+     * 通知弹窗跳转页面
+     *
+     * @param aClass
+     */
+    public UpdateUtil setStartClass(Class<?> aClass) {
+        this.aClass = aClass;
+        return this;
+    }
+
+    /**
+     * 设置图标
+     */
+    public UpdateUtil setIcon(@DrawableRes int icon) {
+        this.icon = icon;
+        return this;
+    }
+
+    /**
+     * 是否需要安装
+     */
+    public UpdateUtil setInstallApk(boolean installApk) {
+        isInstallApk = installApk;
+        return this;
+    }
+
+    /**
+     * 下载监听
+     */
+    public UpdateUtil setUpdateObserver(UpdateObserver updateObserver) {
+        this.updateObserver = updateObserver;
+        return this;
+    }
+
+    /**
+     * 存储目录
+     */
+    public UpdateUtil setFilePath(String filePath) {
+        this.filePath = filePath;
+        return this;
+    }
+
+    /**
+     * 升级
+     */
+    public void request() {
+        if (FormatUtil.isEmpty(title)) {
+            title = "提示";
+        }
+        if (FormatUtil.isEmpty(message)) {
+            message = "是否下载";
+        }
+        if (isShowNotice) {
+            notificationUtil = new NotificationUtil(mActivity, icon, title);
+            if (aClass != null) {
+                notificationUtil.setClass(aClass);
+            }
+        }
+        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
+        if (icon != 0) {
+            builder.setIcon(icon);
+        }
+        builder.setTitle(title);
+        builder.setMessage(message);
+        builder.setPositiveButton("立即更新", new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                dialog.dismiss();
+                progressDialog();
+            }
+        });
+        if (!isLimit) {
+            builder.setNegativeButton("下次提醒", new DialogInterface.OnClickListener() {
+                @Override
+                public void onClick(DialogInterface dialog, int which) {
+                    dialog.dismiss();
+                    if (updateObserver != null) {
+                        updateObserver.onDialogDismiss();
+                    }
+                }
+            });
+        }
+        builder.setCancelable(!isLimit);
+        builder.show();
+
+    }
+
+    /**
+     * 进度条
+     */
+    private void progressDialog() {
+        progressDialog = new ProgressDialog(mContext);
+        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+        progressDialog.setTitle(title);
+        progressDialog.setMessage("正在下载");
+//        progressDialog.setMax(100);
+//        progressDialog.setProgress(0);
+//        // 设置ProgressDialog 的进度条是否不明确
+//        progressDialog.setIndeterminate(false);
+        progressDialog.setCancelable(false);
+        if (icon != 0)
+            progressDialog.setIcon(icon);
+        progressDialog.show();
+//        progressDialog = new AlertDialog.Builder(mActivity);
+//        progressDialog.setTitle(title);
+//        progressDialog.setMessage("正在下载");
+//        View mView = LayoutInflater.from(mActivity).inflate(R.layout.progress_dialog, null);
+//        progressBar = mView.findViewById(R.id.progress);
+////        progressBar.setMax(100);
+////        progressBar.setProgress(0);
+//        progressDialog.setView(mView);
+//        if (icon != 0) {
+//            progressDialog.setIcon(icon);
+//        }
+//        progressDialog.setCancelable(false);
+//        progressDialog.show();
+        notificationUtil.showNotification(1020);
+        download();
+    }
+
+    /**
+     * 下载
+     */
+    private void download() {
+        if (FormatUtil.isEmpty(filePath)) {
+            filePath = mActivity.getPackageName();
+        }
+        DownloadManager.getInstance(mContext).download(downloadUrl, new DownLoadObserver() {
+            @Override
+            public void onComplete() {
+
+            }
+
+            @Override
+            public void onNext(DownloadInfo downloadInfo) {
+                super.onNext(downloadInfo);
+                LogHelper.v(downloadInfo);
+                int progress = (int) (downloadInfo.getProgress() * 1.0f / downloadInfo.getTotal() * 100);
+                if (notificationUtil != null && isShowNotice) {
+                    notificationUtil.updateProgressText(1020, progress, "已下载" + progress + "%");
+                }
+                LogHelper.v("进度" + progress);
+                progressDialog.setMessage("已下载" + progress + "%");
+                progressDialog.setMax(100);
+                progressDialog.setProgress(progress);
+                if (downloadInfo.getProgress() == downloadInfo.getTotal()) {
+                    d.dispose();
+                    if (isInstallApk && FileUtil.ifUrl(downloadInfo.getFile().getPath(), ".apk")) {
+                        installApk(downloadInfo.getFile());
+                    }
+                }
+//                    Message message = new Message();
+//                    message.obj = downloadBean;
+//                    mHandler.sendMessage(message);
+            }
+        });
+//        OkHttpUtil.getInstance(mActivity).downloadFile(downloadUrl).downloads(filePath, new DownloadObserver() {
+//            @Override
+//            public void onNext(DownloadBean downloadBean) {
+//                LogHelper.v(downloadBean);
+//                if (downloadBean != null && downloadBean.status == 0) {
+//                    if (notificationUtil != null && isShowNotice) {
+//                        notificationUtil.updateProgressText(1020, downloadBean.progress, "已下载" + downloadBean.progress + "%");
+//                    }
+//                    LogHelper.v("进度" + downloadBean.progress);
+//                    progressDialog.setMessage("已下载" + downloadBean.progress + "%");
+//                    progressDialog.setMax(100);
+//                    progressDialog.setProgress(downloadBean.progress);
+////                    Message message = new Message();
+////                    message.obj = downloadBean;
+////                    mHandler.sendMessage(message);
+//                } else if (downloadBean != null && downloadBean.status == 1) {
+//                    d.dispose();
+//                    notificationUtil.cancel(1020);
+//                    if (isInstallApk && FileUtil.ifUrl(downloadBean.filePath, ".apk")) {
+//                        installApk(new File(downloadBean.filePath));
+//                    }
+//                }
+//                if (updateObserver != null) {
+//                    updateObserver.onNext(downloadBean);
+//                }
+//            }
+//
+//            @Override
+//            public void onError(Throwable e) {
+//                super.onError(e);
+//                if (updateObserver != null) {
+//                    updateObserver.onError(e);
+//                }
+//            }
+//
+//            @Override
+//            public void onComplete() {
+//                super.onComplete();
+//                if (updateObserver != null) {
+//                    updateObserver.onComplete();
+//                }
+//            }
+//
+//            @Override
+//            public void onSubscribe(Disposable d) {
+//                super.onSubscribe(d);
+//                if (updateObserver != null) {
+//                    updateObserver.onSubscribe(d);
+//                }
+//            }
+//        });
+    }
+
+    /**
+     * 安装下载完成的安装包
+     *
+     * @param file
+     */
+    private void installApk(File file) {
+        //判读版本是否在7.0以上
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+            //在AndroidManifest中的android:authorities值
+            LogHelper.a(file.getAbsolutePath());
+            Uri apkUri = FileProvider.getUriForFile(mActivity, mActivity.getPackageName() + ".fileProvider", file);
+            Intent install = new Intent(Intent.ACTION_VIEW);
+            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            install.setDataAndType(apkUri, "application/vnd.android.package-archive");
+            mActivity.startActivityForResult(install, INSTALL_APK);
+        } else {
+            Intent install = new Intent(Intent.ACTION_VIEW);
+            install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
+            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mActivity.startActivityForResult(install, INSTALL_APK);
+        }
+    }
+
+    public static void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (requestCode == INSTALL_APK) {
+            if (isLimit && isInstallApk) {
+
+            } else {
+
+            }
+        }
+    }
+}

+ 14 - 0
okhttplib/src/main/res/layout/progress_dialog.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="@dimen/padding10">
+
+    <ProgressBar
+        android:id="@+id/progress"
+        style="@android:style/Widget.ProgressBar.Horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/padding7" />
+
+</LinearLayout>