![](/img/trans.png)
[英]Adding a custom listener inside a broadcast receiver gives NPE in Android
[英]Android catch a custom schema link inside a broadcast receiver
我目前正在做一個自定義方案intent-filter來從瀏覽器打開我自己的應用程序。
是否可以打開活動來啟動廣播接收器。
我目前的活動廣播接收器代碼是這樣的:
<action android:name="android.intent.action.VIEW" >
</action>
<category android:name="android.intent.category.DEFAULT" >
</category>
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="shortener.com"
android:scheme="shortener" >
</data>
</intent-filter>
這是我的接收器代碼。 不會觸發。 嘗試了View操作和自定義操作
<receiver android:name="MyReceiver" >
<intent-filter>
<action android:name="com.dg.action.CONFIGURE" >
</action>
<category android:name="android.intent.category.DEFAULT" >
</category>
<data
android:host="shortener.com"
android:scheme="shortener" >
</data>
</intent-filter>
</receiver>
我知道這是舊的,但由於沒有明確的,可接受的答案,嘿。 正如官方文件所說:
... Intent廣播機制..與用於通過Context.startActivity()啟動活動的Intent完全分開。 BroadcastReceiver無法查看或捕獲與startActivity()一起使用的Intent; 同樣,當你廣播一個意圖時,你永遠不會找到或開始一個活動。 這兩個操作在語義上非常不同:使用Intent啟動Activity是一個前台操作,它修改用戶當前正在與之交互的內容; 廣播Intent是用戶通常不知道的后台操作。
來源: Android開發者文檔,BroadcastReceiver
希望能說清楚。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.