Hibok
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

91 linhas
2.7 KiB

  1. import 'dart:async';
  2. import 'package:receive_sharing_intent/receive_sharing_intent.dart';
  3. import 'MessageMgr.dart';
  4. class ReceiveShareFile {
  5. static StreamSubscription _intentDataStreamSubscription;
  6. static List<SharedMediaFile> _sharedFiles;
  7. static String tempFilePath;
  8. static void init() {
  9. // For sharing images coming from outside the app while the app is in the memory
  10. _intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
  11. .listen((List<SharedMediaFile> value) {
  12. // setState(() {
  13. // _sharedFiles = value;
  14. // print("Shared:" + (_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));
  15. // });
  16. // print('#### getfilePath ${value[0].path}');
  17. if (currentIndex == 1) {
  18. if (value != null && value.length > 0) {
  19. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, value[0].path);
  20. }
  21. } else {
  22. // print("### 记录下来了1");
  23. if (value != null && value.length > 0) {
  24. tempFilePath = value[0].path;
  25. }
  26. }
  27. }, onError: (err) {
  28. print("getIntentDataStream error: $err");
  29. });
  30. // For sharing images coming from outside the app while the app is closed
  31. ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
  32. // setState(() {
  33. // _sharedFiles = value;
  34. // print("Shared:" + (_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));
  35. // });
  36. // print('#### getfilePath ${value[0].path}');
  37. if (currentIndex == 1) {
  38. if (value != null && value.length > 0) {
  39. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, value[0].path);
  40. }
  41. } else {
  42. // print("### 记录下来了");
  43. if (value != null && value.length > 0) {
  44. tempFilePath = value[0].path;
  45. }
  46. }
  47. });
  48. // For sharing or opening urls/text coming from outside the app while the app is in the memory
  49. _intentDataStreamSubscription =
  50. ReceiveSharingIntent.getTextStream().listen((String value) {
  51. print('#### getfilePath dddd $value ');
  52. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, value);
  53. }, onError: (err) {
  54. print("getLinkStream error: $err");
  55. });
  56. // For sharing or opening urls/text coming from outside the app while the app is closed
  57. ReceiveSharingIntent.getInitialText().then((String value) {
  58. print('#### getfilePath $value ');
  59. // setState(() {
  60. // _sharedText = value;
  61. // print("Shared: $_sharedText");
  62. // });
  63. });
  64. }
  65. static int currentIndex = 0;
  66. static void start() {
  67. currentIndex = 1;
  68. if (tempFilePath != null) {
  69. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, tempFilePath);
  70. }
  71. }
  72. static dispose() {
  73. currentIndex = 0;
  74. }
  75. }