GithubHelp home page GithubHelp logo

Comments (11)

fankes avatar fankes commented on May 19, 2024 1

成功了!感谢解答

activity?.dataChannel() 改成 activity?.application?.dataChannel() 就能接收到宿主传来的消息了

这个限制是我手动加的,因为会考虑到当前多个 Activity 注册了广播监听的情况,这样在你发送广播的时候,可能已经打开了二级页面,但是之前的页面还是能重复收到广播,所以判断了是否为当前 Activity,如果你没有这个需求,就可以使用 Application 注册全局广播,就不会受到 Activtity 的作用域限制。

from yukihookapi.

fankes avatar fankes commented on May 19, 2024

不用呀,你测试的 Android 版本是什么,我需要知道

from yukihookapi.

cledwynl avatar cledwynl commented on May 19, 2024

安卓13和安卓12

from yukihookapi.

fankes avatar fankes commented on May 19, 2024

在你需要接收广播的 Activity 配置中只需要添加 android:exported="true" 就可以了,你试试。

from yukihookapi.

cledwynl avatar cledwynl commented on May 19, 2024

似乎不行,能确定Activity是android:exported="true"的。而且显示在启动器之后,也需要先从启动器打开模块后才能收到消息。如果先把模块杀后台,再从宿主内跳转到模块Activity,也收不到消息。

我在demo上复现了一下,把intent-filter注释掉了,然后在点击SEND MSG TO MODULE时跳转模块,延迟3秒再发送消息,结果模块没收到消息。

cledwynl@a3292aa

BTW, 我的测试设备是

  • 安卓12,类原生,evolution_venus-userdebug 12 SP2A.220505.002 2206020221
  • 安卓13,MIUI by xiaomi.eu 14.0.31.0.TMCCNXM

from yukihookapi.

fankes avatar fankes commented on May 19, 2024

不可以的,模块和宿主必须保持存活

from yukihookapi.

fankes avatar fankes commented on May 19, 2024

你可以参考 https://github.com/fankes/MIUINativeNotifyIcon 这个项目,这个就是使用二级页面发送的消息

from yukihookapi.

fankes avatar fankes commented on May 19, 2024

你可以描述一下你的使用场景,一般情况下不建议直接做广播通信

from yukihookapi.

cledwynl avatar cledwynl commented on May 19, 2024

你可以描述一下你的使用场景,一般情况下不建议直接做广播通信

我的模块设置界面需要动态展示一些选项(屏蔽底部导航栏的tab),所以需要从宿主那边查询一些信息(导航栏有哪些tab)。所以现在我打算这样做,因为模块设置界面只能从宿主跳转来,所以我认为进入设置界面时宿主一定存活,然后设置界面会向宿主发一条消息,宿主收到消息以后把tab信息发送给设置界面,设置界面再根据信息展示选项。

不可以的,模块和宿主必须保持存活

不太确定你说的存活是否和我理解的相同,我目前的场景下宿主给模块发消息时,模块的设置界面是在前台运行的(虽然这个设置界面是宿主startActivity打开的),我理解这个状态也是“存活”

from yukihookapi.

fankes avatar fankes commented on May 19, 2024

你可以通过非 Activity 发送和接收广播,比如 getApplication(),这样就可以绕过判断是否为当前 Activity 接收广播的限制

from yukihookapi.

cledwynl avatar cledwynl commented on May 19, 2024

成功了!感谢解答

activity?.dataChannel()改成activity?.application?.dataChannel()就能接收到宿主传来的消息了

from yukihookapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.