Hibok
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

96 lignes
2.8 KiB

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