启动活动从网址 [英] Launch Activity From URL
问题描述
我想有我的应用程序启动时,用户浏览到某个网址。我已经找到了几个例子,他们都在体现同样的事情,但它不是为我工作。我已经把意图过滤器下活动,以及一个接收器。
I am trying to have my application launch when the user browses to a certain url. I have found a few examples and they all have the same things in the manifests but it's not working for me. I have put the intent-filter under an Activity as well as a Receiver.
下面是我的清单片段:
<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"></category>
<data android:host="www.urbandictionary.com" android:scheme="http"></data>
</intent-filter>
在活动下,我尝试使用onNewIntent,当它是在一个接收机,我尝试使用onReceiveIntent,都与一个简单的Log.i电话,看它是否解雇与否。我运气不好。
When under the Activity, I tried using onNewIntent and when it was under a Receiver, I tried using onReceiveIntent, both with a simple Log.i call to see if it fired or not. I am not having much luck.
推荐答案
我用这个在我的manifest.xml文件:
I use this in my manifest.xml file:
<activity android:name=".SomeName">
<intent-filter>
<category android:name="android.intent.category.ALTERNATIVE" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="google.com" android:scheme="http" />
</intent-filter>
</activity>
这将启动活动SomeName。我不使用WWW在Android:主机部分可能会有所作为
This will start activity SomeName. I don't use www in the android:host part maybe that will make a difference.
在活动开始就可以得到这就是.COM后面使用(例如)数据:
When the activity starts you can get the data that's behind the .com using (for example):
Uri data = getIntent().getData();
if(data != null && data.getPathSegments().size() >= 2){
List<String> params = data.getPathSegments();
String somestuff = params.get(0);
}
编辑:如果你wan't要能够从活动中检查主机,使用此方法:
If you wan't to be able to check the host from within the activity, use this method:
data.getHost();
这篇关于启动活动从网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!