gpt4 book ai didi

android - 使用 Intents 作为消息传递的一种形式

转载 作者:行者123 更新时间:2023-11-30 02:46:50 25 4
gpt4 key购买 nike

使用 Intent 作为我控制的两个应用之间传递消息的形式有什么缺点吗?

我有两个 apk,它们将始终一起存在于设备上。而且,我想使用明确的 Intent 来回传递消息,而不是创建和管理两个单独的服务。使用显式 Intent 似乎比服务更易于管理。

最佳答案

应用程序之间的通信可以暴露一定的丰富,但如果你真的需要这样做,你只能自定义你的应用程序将知道的权限。然后,您可以使用 BroadcasrReceiver 使用自定义权限安全地交换消息。

定义他们的权限:

<permission android:name="com.yourapp.PERMISSION"
android:protectionLevel="signature"
android:label="@string/permission_label"
android:description="@string/permission_desc">
</permission>

通过设置

<receiver android:name=".MyReceiver"
android:permission="com.yourapp.PERMISSION">
<intent-filter>
<action android:name="com.yourapp.ACTION" />
</intent-filter>
</receiver>

除了这些权限之外,您还可以为他们设置购买 ActivitiesServicesContentProvider

已编辑

Android 中现有进程之间的集成(进程间通信),AIDL(Android 接口(interface)定义语言).

AIDL is particularly useful when different applications need to communicate among themselves to exchange information through a well-defined interface with support for multithreading. Unlike the use of Messenger with Bound Services with AIDL you are required to create a file. AIDL containing the declaration of the integration interface, which helps the client applications to know which operations are available as well as their respective arguments and returns.

关于android - 使用 Intents 作为消息传递的一种形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24876319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com