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

DAr*_*rkO 2 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>
Run Code Online (Sandbox Code Playgroud)

这是我的接收器代码.不会触发.尝试了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>
Run Code Online (Sandbox Code Playgroud)

the*_*jon 9

我知道这是旧的,但由于没有明确的,可接受的答案,嘿.正如官方文件所说:

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

来源:Android开发者文档,BroadcastReceiver

希望能说清楚.