joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 787 forks source link

download manager cold not resolve downloaded file path #205

Open 841660202 opened 6 years ago

841660202 commented 6 years ago
    "react": "16.2.0",
    "react-native": "0.53.0",
    "rn-fetch-blob": "^0.10.12"
import React, { Component } from "react"
import RNFetchBlob from "rn-fetch-blob"
import { View } from "react-native"
import { Button, WhiteSpace } from "antd-mobile-rn"

export default class Blob extends Component {

  download = () => {
    const {android} = RNFetchBlob

    RNFetchBlob.config({
      addAndroidDownloads : {
        useDownloadManager : true,
        title : '软件下载中。。。',
        description : '',
        mime : 'application/vnd.android.package-archive',
        mediaScannable : true,
        notification : true,
      }
    })
      .fetch('GET', `http://issuecdn.baidupcs.com/issue/netdisk/apk/BaiduNetdisk_7.15.1.apk`)
      .then((res) => {
        android.actionViewIntent(res.path(), 'application/vnd.android.package-archive')
      })
  };

  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center" }}>
        <Button onClick={this.download.bind(this)}>
          下载安装包
        </Button>
        <WhiteSpace/>
      </View>
    )
  }
}

wechatimg98

arbabi2010 commented 5 years ago

I solved this problem with this solution

var RNFS = require('react-native-fs'); import RNFetchBlob from 'rn-fetch-blob';

let downloadDest = ${RNFS.ExternalStorageDirectoryPath}/Download/123.jpg;

RNFetchBlob.config({ addAndroidDownloads: { useDownloadManager: true, path: downloadDest, notification: true, mime: '/' }).then((res) => { RNFetchBlob.android.actionViewIntent(res.path(), '/') })