Hibok
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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