搭上Android的广播接收器内的自定义架构链接 [英] Android catch a custom schema link inside a broadcast receiver

查看:126
本文介绍了搭上Android的广播接收器内的自定义架构链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在做一个自定义方案的意图过滤器,从浏览器中打开自己的应用程序。

是否有可能不是开放活动推出的广播接收机。

我目前的code的活性广播接收机是这样的:

 <作用机器人:名字=android.intent.action.VIEW>
            < /作用>            <类机器人:名字=android.intent.category.DEFAULT>
            < /类别>
            <类机器人:名字=android.intent.category.BROWSABLE/>            <数据
                机器人:主机=shortener.com
                机器人:计划=缩略>
            < /数据>
        &所述; /意图滤光器>

下面是我的接收器code。不会触发。尝试了查看动作和自定义操作

 <接收机器人:名字=MyReceiver>
            &所述;意图滤光器>
                <作用机器人:名字=com.dg.action.CONFIGURE>
                < /作用>
                <类机器人:名字=android.intent.category.DEFAULT>
                < /类别>
                <数据
                    机器人:主机=shortener.com
                    机器人:计划=缩略>
                < /数据>
            &所述; /意图滤光器>
        < /接收器>


解决方案

我知道这是旧的,但因为有它没有明确和接受的答案,什么哎。作为官方文档所说的那样:


  

...的意图广播机制..是被用来开始Context.startActivity活动意图完全独立的()。有没有办法为一个BroadcastReceiver看到或与startActivity用于捕获的Intent();同样,当您广播一个Intent,你永远不会找到或启动活动。这两个操作在语义上非常不同的:开始用一意图一个活动是修改什么用户当前使用交互的前台操作;广播的意图是,用户通常不知道一个后台操作


来源: Android开发者文档,广播接收器

希望这是清楚。

I am currently doing a custom scheme intent-filter to open my own app from the browser.

Is it possible to instead opening an activity to launch a broadcast receiver.

My current code for the activity broadcast receiver is like this:

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

Here is my receiver code. Doesn't trigger. tried a View action and a custom action

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

解决方案

I know this is old, but since there's no clear and accepted answer on it, what the hey. As the official documentation puts it:

...the Intent broadcast mechanism .. is completely separate from Intents that are used to start Activities with Context.startActivity(). There is no way for a BroadcastReceiver to see or capture Intents used with startActivity(); likewise, when you broadcast an Intent, you will never find or start an Activity. These two operations are semantically very different: starting an Activity with an Intent is a foreground operation that modifies what the user is currently interacting with; broadcasting an Intent is a background operation that the user is not normally aware of.

Source: Android Developer Documentation, BroadcastReceiver

Hope that makes it clear.

这篇关于搭上Android的广播接收器内的自定义架构链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆