react-native使用RNFetchBlob 更新安卓包

react-native-fetch-blob链接: https://github.com/wkh237/react-native-fetch-blob

示例代码:

import RNFetchBlob from 'react-native-fetch-blob';

let dirs = RNFetchBlob.fs.dirs;
let android = RNFetchBlob.android;
RNFetchBlob.config({
        addAndroidDownloads: {
            // 调起原生下载管理
            useDownloadManager: true,
            // 你想要设置的下载的安装包保存的名字
            title: '盛云.apk',
            // 下载时候顶部通知栏的描述
            description: '下载完成之后将会自动安装',
            // 下载的文件格式
            mime: 'application/vnd.android.package-archive',
            // 下载完成之后扫描下载的文件
            mediaScannable: true,
            // 通知栏显示下载情况
            notification: true,
            // 文件下载的同时缓存起来,提高操作效率
            fileCache: true,
            path: dirs.DownloadDir + '/盛云.apk'
        }
    })
    .fetch('GET', `${this.state.apkUrl}`)
    .progress((received, total) => {
        // todo:貌似下载进度无法响应
        // console.log('下载进度:' + Math.floor((received / total) * 100) + '%');
    })
    .then(res => {
        android.actionViewIntent(
            dirs.DownloadDir + '/盛云.apk',
            'application/vnd.android.package-archive'
        );
    })
    .catch(err => {
        console.warn('下载失败');
        console.warn(err);
    });

你可能感兴趣的:(react-native使用RNFetchBlob 更新安卓包)