1

我们的android系统支持多用户功能。我想从其他应用程序启动我的服务器,例如使用命令startService(intent)的app1,app2。 根据谷歌的文档https://source.android.com/devices/tech/admin/multiuser-apps.html。 我需要设置android:singleUser =“true”来确保我的服务只在多个用户的android系统中的一个实例中运行。但是当我在其他应用程序startservice,我有以下异常:如何让我的服务仅在多用户android系统中的一个实例中运行?

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禁用:单用户=“真”。如果我没有添加android:singleUser =“true”,它运行良好,但我的服务在后台运行的实例不止一个。 我的问题是如何让我的服务只能在其他应用程序中使用startService(intent)在单个实例中运行? 我的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> 

非常感谢。

回答

0

是的,需要申明系统应用程序。也可以在System UserHandler中使用bindServiceAsUser()。

1

正如您链接的文档所言:“只有系统应用程序当前可以使用此功能”。如果您的产品可行,请将您的应用程序设为系统应用程序。

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