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. 確保您的應用程序是特權。所以你應該讓你的應用系統簽名
相關問題