【问题标题】:Launch Activity From URL从 URL 启动活动
【发布时间】:2010-03-05 17:24:45
【问题描述】:

我试图在用户浏览到某个 url 时启动我的应用程序。我找到了一些示例,它们在清单中都有相同的内容,但这对我不起作用。我已将意图过滤器放在 Activity 和 Receiver 下。

这是我的清单 sn-p:

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

在 Activity 下,我尝试使用 onNewIntent,当它在 Receiver 下时,我尝试使用 onReceiveIntent,两者都通过一个简单的 Log.i 调用来查看它是否触发。我运气不太好。

【问题讨论】:

标签: android android-intent android-activity manifest


【解决方案1】:

我在 manifest.xml 文件中使用它:

<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。我不在 android:host 部分使用 www 可能会有所作为。

当活动开始时,您可以使用(例如)获取 .com 背后的数据:

Uri data = getIntent().getData();
if(data != null && data.getPathSegments().size() >= 2){
    List<String> params = data.getPathSegments();
    String somestuff = params.get(0);
}

编辑:如果您无法从活动中检查主机,请使用此方法:

data.getHost();

【讨论】:

  • @ArslanAhmad 当然,看看我的回答;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-17
  • 2011-10-25
  • 1970-01-01
相关资源
最近更新 更多