简体   繁体   English

如何打开刚从react-native Webview下载的apk文件?

[英]How can I open apk file I just download from react-native Webview?

I am trying to use react-native-webview to download Android apk file. 我正在尝试使用react-native-webview下载Android apk文件。 It could download apk file actually! 它实际上可以下载apk文件!

But How can I know when file is download success and get file path or automatically install the apk file I just download? 但是,如何知道文件何时下载成功并获取文件路径或自动安装我刚刚下载的apk文件?

is there any good ideal to make it happen? 有没有实现它的良好理想? very thanks 很感谢

Once downloaded to your device path, you can try this with two modules. 下载到设备路径后,您可以使用两个模块进行尝试。

You must have two modules installed and available. 您必须安装两个模块并且可用。 react-native-file-viewer and react-native-document-picker react-native-file-viewerreact-native-document-picker

Example

import FileViewer from 'react-native-file-viewer';
import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker';

DocumentPicker.show({
  filetype: [DocumentPickerUtil.allFiles()],
}, (error, res) => {
  if(res) {
    FileViewer.open(res.uri)
    .then(() => {
      // success
    })
    .catch(_err => {
      // error
    });
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM