使用Android获取url
我正在尝试获取为打开应用程序而单击的URL。我只是很难找到我能从哪里得到这些信息。我有一个清单,点击时打开应用程序。链接将是“”,我正试图将其交给要处理的应用程序使用Android获取url,android,android-intent,Android,Android Intent,我正在尝试获取为打开应用程序而单击的URL。我只是很难找到我能从哪里得到这些信息。我有一个清单,点击时打开应用程序。链接将是“”,我正试图将其交给要处理的应用程序 <intent-filter> <data android:scheme="http" android:host="host.com" android:pathPrefix="/file.html" />
<intent-filter>
<data android:scheme="http"
android:host="host.com"
android:pathPrefix="/file.html" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
您应该能够通过以下方式获得活动中的意图数据:
Uri uri = this.getIntent().getData();
URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath());
你必须用try/catch来包围 基本上,一旦获得Uri(即,
getIntent().getData()
),就可以将完整的url读取为Uri.toString()
。假设您的android:host
有效并已设置,您还可以通过调用uri.getEncodedQuery()
来获取实际的查询数据
如果需要,以下是工作示例中的更多详细信息:
uri.toString()
products“”,并且uri.getEncodedQuery()
products“ll=43.455095,44.177416”希望有帮助 我将当前的OnCreate方法添加到顶部。但似乎仍然不起作用。我的onCreate方法似乎没有被调用,据我所知,它将在系统调用onCreate时被调用,并通过重写它重定向到我创建的onCreate。
Uri uri = this.getIntent().getData();
URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath());
Uri uri = this.getIntent().getData();
try
{
URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath());
}
catch (MalformedURLException e)
{
}
<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:host="boo.acme.com"
android:scheme="http" />
</intent-filter>
Uri uri = this.getIntent().getData();