Android catch a custom schema link inside a broadcast receiver

对着背影说爱祢 提交于 2019-12-24 00:25:38

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/14579303/android-catch-a-custom-schema-link-inside-a-broadcast-receiver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!