2016-12-05 85 views
0

在我的Android應用程序,我趕上了PACKAGE_ADDED廣播:爲PACKAGE_ADDED意圖過濾特定包

<receiver android:name=".OnAppInstall"> 
    <intent-filter> 
     <action android:name="android.intent.action.PACKAGE_INSTALL" /> 
     <action android:name="android.intent.action.PACKAGE_ADDED" /> 
     <data android:scheme="package" /> 
    </intent-filter> 
</receiver> 

我的應用程序只關注安裝特定的配套應用的。意圖中的數據字符串爲:package:com.acme.myapp。意圖數據Uri是OpaqueUri的實例; getHost()getPath()getQuery()都返回空值。

我可以以某種方式創建一個意圖過濾器,只允許一個特定的包ID意圖?

回答

0

請嘗試以下操作。

<intent-filter> 
<action android:name="android.intent.action.PACKAGE_ADDED" /> 
<data android:scheme="package" 
     android:sspPrefix="com.acme.myapp" /> 
</intent-filter> 

這與相應的API調用here匹配。

+0

僅限Android 4.4+。儘管如此,總比沒有好。至少在早期版本中,它並不妨礙過濾器的工作。 –

+0

在5.0仿真器上運行,使用sspPrefix接收器不會觸發,沒有它:( –

+0

帶有'sspPattern'的數據過濾器在6.0上工作。 –