ソースを参照

用户在其他应用点击媒体文件分享可以用天天静听打开

onecold 1 年間 前
コミット
c4b60b3b26

+ 21 - 17
entry/src/main/ets/entryability/EntryAbility.ets

@@ -75,13 +75,10 @@ export default class EntryAbility extends UIAbility {
         AppStorage.setOrCreate('context', this.context);
         hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
 
-        let timeout = 5000
-        if(Utility.isNoble())
-            timeout = 3000
         setTimeout(async ()=>{
             this.loadDoWant(want)
-            // await this.handleParam(want)
-        },timeout)
+            await this.handleParam(want)
+        },1000)
 
         this.handleWeChatCallIfNeed(want)
 
@@ -91,7 +88,7 @@ export default class EntryAbility extends UIAbility {
         hilog.info(0x0000, 'testTag', `onNewWant, want=${JSON.stringify(want)}`);
         super.onNewWant(want, launchParam);
         this.loadDoWant(want)
-        // await this.handleParam(want)
+        await this.handleParam(want)
         this.handleWeChatCallIfNeed(want)
 
     }
@@ -109,20 +106,27 @@ export default class EntryAbility extends UIAbility {
             return;
         }
         hilog.info(0x0000, 'testTag', `onCreate or onNewWant, uri=${uri}`);
-        const eventData: emitter.EventData = {
-            data: {
-                message: uri
+
+        this.doSendEmit(uri)
+    }
+    //广播通知打开播放器播放视频或者音频
+    doSendEmit(uri:string){
+        setTimeout(async ()=>{
+            let eventData: emitter.EventData = {
+                data: {
+                    message: uri
+                }
+            };
+            if(Utility.isMeidaByExtension(uri)){
+                emitter.emit({ eventId: 2 }, eventData); // 发送音频打开广播事件
+            }else{
+                emitter.emit({ eventId: 1 }, eventData); // 发送视频打开广播事件
             }
-        };
-        if(Utility.isMeidaByExtension(uri)){
-            emitter.emit({ eventId: 2 }, eventData); // 发送音频打开广播事件
-        }else{
-            emitter.emit({ eventId: 1 }, eventData); // 发送视频打开广播事件
-        }
+        },300)
 
     }
 
-    // 华为分享拉起接收
+    // 华为分享拉起接收   处理分享数据
     // 1. 改造 handleParam 为异步函数,让其返回 Promise
     async handleParam(want: Want) {
         try {
@@ -133,7 +137,7 @@ export default class EntryAbility extends UIAbility {
             for (const record of records) {
                 if (record.uri) {
                     uri = record.uri;
-
+                    this.doSendEmit(uri)
                     break;
                 }
             }

+ 0 - 142
entry/src/main/ets/entryability/ShareUIAbility.ets

@@ -1,142 +0,0 @@
-import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
-import { window } from '@kit.ArkUI';
-import { systemShare } from '@kit.ShareKit';
-import { BusinessError, emitter } from '@kit.BasicServicesKit';
-import { hilog } from '@kit.PerformanceAnalysisKit';
-import { AppUtil, GlobalContext, LogUtil, StrUtil } from '@pura/harmony-utils';
-import { Utility } from '../common/util/Utility';
-import { DemoConstants } from './DemoConstants';
-import { WXApi, WXEventHandler } from '../common/util/WXApiWrap';
-
-
-export default class ShareUIAbility extends UIAbility {
-  //一多断点开发
-  private uiContext?: UIContext;
-  private onWindowSizeChange: (windowSize: window.Size) => void = (windowSize: window.Size) => {
-    let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint();
-    AppStorage.setOrCreate('currentWidthBreakpoint', widthBp);
-    let heightBp: HeightBreakpoint = this.uiContext!.getWindowHeightBreakpoint();
-    AppStorage.setOrCreate('currentHeightBreakpoint', heightBp);
-  };
-
-  onAvoidAreaChange = (data: window.AvoidAreaOptions) => {
-
-    let topRectHeight =  px2vp(data.area.topRect.height);
-    AppStorage.setOrCreate('topRectHeight', topRectHeight);
-    LogUtil.info('onecold onAvoidAreaChange topRectHeight = '+topRectHeight);
-    let bottomRectHeight =  px2vp(data.area.bottomRect.height);
-    AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight);
-
-  }
-
-  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
-    AppStorage.setOrCreate('context', this.context);
-    let timeout = 2000
-    // if(Utility.isNoble())
-    //   timeout = 2000
-    setTimeout(()=>{
-      this.handleShare(want)//分享打开的音频
-    },timeout)
-    this.handleWeChatCallIfNeed(want)
-  }
-
-  onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
-    hilog.info(0x0000, 'ShareUIAbility', `onNewWant, want=${JSON.stringify(want)}`);
-    super.onNewWant(want, launchParam);
-    this.handleShare(want)
-
-    this.handleWeChatCallIfNeed(want)
-  }
-
-
-  private handleWeChatCallIfNeed(want: Want) {
-    WXApi.handleWant(want, WXEventHandler)
-  }
-
-  //处理其他app点击分享的视频或音频的打开本app播放器播放视频或者音频
-  handleShare(want: Want){
-    systemShare.getSharedData(want)
-      .then((data: systemShare.SharedData) => {
-        data.getRecords().forEach((record: systemShare.SharedRecord) => {
-
-          let uri = record.uri
-          if (uri == null || uri == undefined|| StrUtil.isEmpty(uri)) {
-            console.info('uri is invalid');
-            return;
-          }
-          hilog.info(0x0000, 'testTag', `onCreate or onNewWant, uri=${uri}`);
-          const eventData: emitter.EventData = {
-            data: {
-              message: uri
-            }
-          };
-          if(Utility.isMeidaByExtension(uri)){
-            emitter.emit({ eventId: 2 }, eventData); // 发送音频打开广播事件
-          }else{
-            emitter.emit({ eventId: 1 }, eventData); // 发送视频打开广播事件
-          }
-          // 处理分享数据
-        });
-      })
-      .catch((error: BusinessError) => {
-        console.error(`Failed to getSharedData. Code: ${error.code}, message: ${error.message}`);
-        this.context.terminateSelf();
-      });
-
-
-  }
-
-
-  onWindowStageCreate(windowStage: window.WindowStage): void {
-    // Main window is created, set main page for this ability
-    AppUtil.init(this.context);
-
-    // PreferencesUtil.init(CommonConstants.PLAY_STORE)
-    // Main window is created, set main page for this ability
-
-
-    //1.获取应用主窗口。
-    let windowClass: window.Window | null = null;
-    windowStage.getMainWindow((err: BusinessError, data) => {
-      windowClass = data;
-
-      globalThis.windowClass = data // 赋值给全局变量windowClass
-      let avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
-      let topRectHeight =  px2vp(avoidArea.topRect.height);
-      AppStorage.setOrCreate('topRectHeight', topRectHeight);
-      LogUtil.info('onecold  topRectHeight = '+topRectHeight);
-      windowClass.on('avoidAreaChange', this.onAvoidAreaChange)
-    })
-    AppStorage.setOrCreate('windowStage',windowStage);
-
-
-
-
-    GlobalContext.getContext().setObject('windowClass',windowClass)
-    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
-
-    windowStage.loadContent('pages/SplashIndex', (err, data) => {
-      if (err.code) {
-        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
-        return;
-      }
-
-      //一多断点开发
-      windowStage.getMainWindow().then((data: window.Window) => {
-        this.uiContext = data.getUIContext();
-        let widthBp: WidthBreakpoint = this.uiContext.getWindowWidthBreakpoint();
-        let heightBp: HeightBreakpoint = this.uiContext.getWindowHeightBreakpoint();
-        AppStorage.setOrCreate('currentWidthBreakpoint', widthBp);
-        AppStorage.setOrCreate('currentHeightBreakpoint', heightBp);
-        data.on('windowSizeChange', this.onWindowSizeChange);
-      }).catch((err: BusinessError) => {
-        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
-      });
-      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
-    });
-
-    DemoConstants.windowStage = windowStage
-
-
-  }
-}

+ 1 - 1
entry/src/main/ets/pages/SettingPage.ets

@@ -720,7 +720,7 @@ export struct SettingPage {
             Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
             //播放列表透明
             Row() {
-              Text('播放列表透明')
+              Text('播放列表背景透明')
                 .margin({ left: 18 })
                 .fontSize(15)
                 .fontColor(Color.Gray)

+ 14 - 69
entry/src/main/module.json5

@@ -57,29 +57,26 @@
               {
                 "scheme": "file",
                 "utd": "general.audio",
-                "linkFeature": "FileOpen"
+                "maxFileSupported": 1
+              },
+              {
+                "scheme": "file",
+                "utd": "general.video",
+                "maxFileSupported": 1
               },
 
               {
                 "scheme": "file",
-                "utd":"general.video",
+                "type": "audio/*",
                 "linkFeature": "FileOpen",
+                "maxFileSupported": 1
               },
-
-
-
-//              {
-//                "scheme": "file",
-//                "type": "audio/*",
-//                "linkFeature": "FileOpen",
-//                "maxFileSupported": 1
-//              },
-//              {
-//                "scheme": "file",
-//                "type": "video/*",
-//                "linkFeature": "FileOpen",
-//                "maxFileSupported": 1
-//              }
+              {
+                "scheme": "file",
+                "type": "video/*",
+                "linkFeature": "FileOpen",
+                "maxFileSupported": 1
+              }
             ],
             "entities": [
               "entity.system.home"
@@ -88,58 +85,6 @@
           }
         ]
       },
-//      {
-//        "name": "ShareUIAbility",
-//        "srcEntry": "./ets/entryability/ShareUIAbility.ets",
-//        "description": "$string:EntryAbility_desc",
-//        "icon": "$media:icon",
-//        "label": "$string:EntryAbility_label",
-//        "startWindowIcon": "$media:icon",
-//        "startWindowBackground": "$color:start_window_background",
-//        "orientation": "portrait",
-//        "exported": true,
-//        "backgroundModes": [
-//          // 长时任务类型的配置项
-//          "audioPlayback"
-//        ],
-//        "skills": [
-//          {
-//            "actions": [
-//              "ohos.want.action.sendData",
-//            ],
-//
-//            // 目标应用在配置支持接收的数据类型时,需穷举支持的UTD,比如:支持全部图片类型,可声明:general.image
-//            // maxFileSupported 对于归属指定类型的文件,标识一次支持接收的最大数量。默认为0,代表不支持此类文件的分享。文件类型归属关系参考:@ohos.data.uniformTypeDescriptor (标准化数据定义与描述)
-//            "uris": [
-//
-//              {
-//                "scheme": "file",
-//                "utd": "general.audio",
-//                "linkFeature": "FileOpen"
-//              },
-//              {
-//                "scheme": "file",
-//                "type": "audio/*",
-//                "linkFeature": "FileOpen",
-//                "maxFileSupported": 1
-//              },
-
-
-//              {
-//                "scheme": "file",
-//                "type": "video/*",
-//                "linkFeature": "FileOpen",
-//                "maxFileSupported": 1
-//              },
-//              {
-//                "scheme": "file",
-//                "utd":"general.video",
-//                "linkFeature": "FileOpen"
-//              }
-//            ]
-//          }
-//        ]
-//      }
 
     ],