Hibok
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

107 rindas
3.2 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 int mLastClickTime = 0;
  9. static final int TIME_INTERVAL = 3000;
  10. static void init() {
  11. // For sharing images coming from outside the app while the app is in the memory
  12. _intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
  13. .listen((List<SharedMediaFile> value) {
  14. // setState(() {
  15. // _sharedFiles = value;
  16. // print("Shared:" + (_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));
  17. // });
  18. // print('#### getfilePath ${value[0].path}');
  19. if (currentIndex == 1) {
  20. int nowTime = DateTime.now().millisecondsSinceEpoch;
  21. if (nowTime - mLastClickTime > TIME_INTERVAL) {
  22. if (value != null && value.length > 0) {
  23. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, value[0].path);
  24. }
  25. }
  26. } else {
  27. // print("### 记录下来了1");
  28. if (value != null && value.length > 0) {
  29. tempFilePath = value[0].path;
  30. }
  31. }
  32. }, onError: (err) {
  33. print("getIntentDataStream error: $err");
  34. });
  35. // For sharing images coming from outside the app while the app is closed
  36. ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
  37. // setState(() {
  38. // _sharedFiles = value;
  39. // print("Shared:" + (_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));
  40. // });
  41. // print('#### getfilePath ${value[0].path}');
  42. if (currentIndex == 1) {
  43. int nowTime = DateTime.now().millisecondsSinceEpoch;
  44. if (nowTime - mLastClickTime > TIME_INTERVAL) {
  45. // do something
  46. if (value != null && value.length > 0) {
  47. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, value[0].path);
  48. mLastClickTime = nowTime;
  49. }
  50. } else {}
  51. } else {
  52. // print("### 记录下来了");
  53. if (value != null && value.length > 0) {
  54. tempFilePath = value[0].path;
  55. }
  56. }
  57. });
  58. // For sharing or opening urls/text coming from outside the app while the app is in the memory
  59. _intentDataStreamSubscription =
  60. ReceiveSharingIntent.getTextStream().listen((String value) {
  61. print('#### getfilePath $value ');
  62. // setState(() {
  63. // _sharedText = value;
  64. // print("Shared: $_sharedText");
  65. // });
  66. }, onError: (err) {
  67. print("getLinkStream error: $err");
  68. });
  69. // For sharing or opening urls/text coming from outside the app while the app is closed
  70. ReceiveSharingIntent.getInitialText().then((String value) {
  71. print('#### getfilePath $value ');
  72. // setState(() {
  73. // _sharedText = value;
  74. // print("Shared: $_sharedText");
  75. // });
  76. });
  77. }
  78. static int currentIndex = 0;
  79. static void start() {
  80. currentIndex = 1;
  81. if (tempFilePath != null) {
  82. MessageMgr().emit(MessageMgr.RECEIVE_THIRD_SHARE, tempFilePath);
  83. }
  84. }
  85. static dispose() {
  86. currentIndex = 0;
  87. }
  88. // if (await CustomUI.showPhotoPermissionSetting(context)) {
  89. }