如何使我的服务只在一个实例多用户Android系统的运行?

问题描述 投票:2回答:4

我们的Android系统支持多用户功能。我想从其他应用程序启动我的服务器,像APP1,APP2用命令startService(意图)。每谷歌的在https://source.android.com/devices/tech/admin/multiuser-apps.html文件。我需要设置的android:单用户=“true”以确保我的服务只在一个实例多用户Android系统的运行。但是当我在其他应用程序startservice,我有以下异常:

Not allowed to start service Intent { act=com.xx.xxx.action.Start pkg=com.xx.xxx (has extras) } without permission not exported from uid 1000

它似乎安卓:出口=“真”是由Android禁用:单用户=“真”。如果我没有添加机器人:单用户=“真”,它工作得很好,但也有在后台运行,我的服务不止一个实例。我的问题是如何才能让我的服务只在一个单一实例与startService(意向)从其他应用程序运行?我的Manifest.xml的配置如下:

    <application
        android:name=".App"
        android:label="@string/app_name"
        android:directBootAware="true"
        android:multiprocess="false"
        android:persistent="true">
        <service
            android:name=".MyService"
            android:singleUser="true"
            android:exported="true"
            android:permission="com.xx.permission.xx">
            <intent-filter>
                <action android:name="com.xx.xx.action.xx" />
            </intent-filter>
        </service>
</Application>

非常感谢。

android android-service android-manifest android-service-binding
4个回答
1
投票

当你链接的文件说:“只有系统应用目前可以使用该功能”。如果这是你的产品是可行的,让你的应用程序的系统应用。


0
投票

是的,需要声明的应用程序作为系统应用。还使用bindServiceAsUser()与系统UserHandler。


0
投票
  1. 使Android:出口和android:单用户为真
  2. 添加权限INTERACT_ACROSS_USERS
  3. 确保你的应用程序是特权。所以你应该让你的应用系统签名

0
投票

您需要INTERACT_ACROSS_USERS_FULL获准在允许从非主用户绑定到单个实例的服务。这是一个仅签署权限,以便您的应用需要与平台密钥签署。

© www.soinside.com 2019 - 2024. All rights reserved.