Nenhuma descrição

android.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2016 wkh237@github. All rights reserved.
  2. // Use of this source code is governed by a MIT-style license that can be
  3. // found in the LICENSE file.
  4. import {
  5. NativeModules,
  6. DeviceEventEmitter,
  7. Platform,
  8. NativeAppEventEmitter,
  9. } from 'react-native'
  10. const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
  11. /**
  12. * Send an intent to open the file.
  13. * @param {string} path Path of the file to be open.
  14. * @param {string} mime MIME type string
  15. * @return {Promise}
  16. */
  17. function actionViewIntent(path:string, mime:string = 'text/plain') {
  18. if(Platform.OS === 'android')
  19. return RNFetchBlob.actionViewIntent(path, mime)
  20. else
  21. return Promise.reject('RNFetchBlob.android.actionViewIntent only supports Android.')
  22. }
  23. function getContentIntent(mime:string) {
  24. if(Platform.OS === 'android')
  25. return RNFetchBlob.getContentIntent(mime)
  26. else
  27. return Promise.reject('RNFetchBlob.android.getContentIntent only supports Android.')
  28. }
  29. function addCompleteDownload(config) {
  30. if(Platform.OS === 'android')
  31. return RNFetchBlob.addCompleteDownload(config)
  32. else
  33. return Promise.reject('RNFetchBlob.android.addCompleteDownload only supports Android.')
  34. }
  35. function getSDCardDir() {
  36. if(Platform.OS === 'android')
  37. return RNFetchBlob.getSDCardDir()
  38. else
  39. return Promise.reject('RNFetchBlob.android.getSDCardDir only supports Android.')
  40. }
  41. function getSDCardApplicationDir() {
  42. if(Platform.OS === 'android')
  43. return RNFetchBlob.getSDCardApplicationDir()
  44. else
  45. return Promise.reject('RNFetchBlob.android.getSDCardApplicationDir only supports Android.')
  46. }
  47. export default {
  48. actionViewIntent,
  49. getContentIntent,
  50. addCompleteDownload,
  51. getSDCardDir,
  52. getSDCardApplicationDir,
  53. }