interupting link to my app

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 ie 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 Intent s.

The rules of intent resolution actually determine whether a particular Intent matches any IntentFilter s. 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 IntentFilter s, 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.

链接地址: http://www.djcxy.com/p/57982.html

上一篇: JNA内存泄漏

下一篇: interupting链接到我的应用程序