interupting链接到我的应用程序 [英] interupting link to my app

查看:124
本文介绍了interupting链接到我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。荫使用下面的code到interupt链接到我的应用程序的

 <意向滤光器>
    <作用机器人:名称=android.intent.action.VIEW/>
    <类机器人:名称=android.intent.category.DEFAULT/>
    <类机器人:名称=android.intent.category.BROWSABLE/>
    <数据机器人:计划=HTTP机器人:主机=twitter.com/>
    <数据机器人:计划=HTTP机器人:主机=facebook.com/>
&所述; /意图滤光器>
 

但问题是,我需要设置数据计划和主机在运行时也就是我可以添加或删除主机在运行。所以,请人帮我设定数据计划和主机在runtime.I的价值是用低于code,但它不能正常工作

  IntentFilter的过滤器=新的IntentFilter();
filter.addAction(android.intent.action.VIEW);
filter.addCategory(android.intent.category.DEFAULT);
filter.addCategory(android.intent.category.BROWSABLE);
filter.addDataScheme(HTTP);
filter.addDataAuthority(www.facebook.com,NULL);
RecieveBroadcaster接收器=新RecieveBroadcaster();
registerReceiver(接收机,过滤器);
 

解决方案

从严格意义上讲,相当于 ACTION_VIEW 字符串是活动的行动按约定;您将它变成你的清单中的活动意图过滤器元素的事实,,使的是一个活动的行动!该系统监听这些对您的应用程序的代表,这基本上是你为什么不(不能),听他们自己。该 Context.startActivity()方法生成这些意图秒。

意图解决的规则实际上是确定是否为特定的意图匹配任何的IntentFilter 秒。对于活动意图,可以存在多个匹配,并且通常显示选配接口,以便用户可以选择一个目标。

有三意图流,从来没有跨: startActivity() sendBroadcast() startService()。这些都是通过方法上下文启动,每个人都有一个特定的目标活动的BroadcastReceiver 服务分别。

这是一个简单的事情,成立了的BroadcastReceiver (而不是 ReceiveBroadcaster 你甚至尝试了code吗?)让你感兴趣的事件,然后用 Context.startActivity()意图您想。你甚至可以使用自定义操作,所以你知道它是由接收器引发的,而不是用户。

唯一的问题是:有没有广播事件,你可以安排领取?有可能是系统事件,你可以注册,或者您可以生成自定义事件自己,通过 Context.sendBroadcast()

记住,你可以检查传入意图的活性开始,而前进相同或修改意图如果不完全匹配,你所期待的。当你正确的决定,你不能动态地修改的IntentFilter 取值活动的集合,所以你必须检查每个请求的主机。

记住,你也可以在你的清单中注册的接收器为好,并具有实现由系统自动调用。

I have a problem. Iam using the below code to interupt links to my app as

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http" android:host="twitter.com"/>
    <data android:scheme="http" android:host="facebook.com"/>
</intent-filter>

But the problem is that I need to set data scheme and host at runtime i.e. I can add or delete the host at runtime. SO please somebody help me in setting the value of data scheme and host at runtime.I am using below code but it is not working

IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.VIEW");
filter.addCategory("android.intent.category.DEFAULT");
filter.addCategory("android.intent.category.BROWSABLE");
filter.addDataScheme("http");
filter.addDataAuthority("www.facebook.com", null);
RecieveBroadcaster  receiver = new RecieveBroadcaster();
registerReceiver(receiver, filter);

解决方案

Strictly speaking, the string corresponding to ACTION_VIEW is an activity action by convention; the fact that you place it into the intent-filter element of an activity in your manifest, makes it an activity action! The system listens for these on your application's behalf, which is basically why you don't (can't) listen for them yourself. The Context.startActivity() method generates these Intents.

The rules of intent resolution actually determine whether a particular Intent matches any IntentFilters. For activity intents, there may be multiple matches, and that usually displays the "Chooser" interface, so the user can select a target.

There are three Intent "streams" that never cross: startActivity(), sendBroadcast() and startService(). These are all initiated via methods in Context and each has a specific target Activity, BroadcastReceiver and Service respectively.

It is a simple matter to set up a BroadcastReceiver (not ReceiveBroadcaster did you even try that code?) to get the events you are interested in, and then use Context.startActivity() with the Intent you want. You can even use a custom action, so you know it was triggered by the receiver, and not the user.

The only question is: is there a broadcast event you can arrange to receive? There may be a system event you can register for, or you may be able to generate a custom event yourself, via Context.sendBroadcast().

Remember you can inspect the incoming Intent your activity was started with, and "forward" the same or a modified Intent if it doesn't exactly match what you are looking for. As you correctly determined, you cannot dynamically alter an activity's set of IntentFilters, so you will have to inspect the host of every request.

Remember you can also register receivers in your manifest as well, and have that implementation called automatically by the system.

这篇关于interupting链接到我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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