Android捕获广播接收器内的自定义架构链接

时间:2013-01-29 09:15:28

标签: android android-intent

我目前正在使用自定义方案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>

这是我的接收器代码。不会触发。尝试了查看操作和自定义操作

 <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>

1 个答案:

答案 0 :(得分:8)

我知道这已经过时了,但由于没有明确的答案,所以嘿。正如官方文件所说:

  

... Intent广播机制..与用于使用Context.startActivity()启动活动的Intents完全分开。 BroadcastReceiver无法查看或捕获与startActivity()一起使用的Intent;同样,当你广播一个意图时,你永远不会找到或开始一个活动。这两个操作在语义上非常不同:使用Intent启动Activity是一个前台操作,它修改用户当前正在与之交互的内容;广播Intent是用户通常不知道的后台操作。

来源:Android Developer Documentation, BroadcastReceiver

希望能说清楚。