如何从浏览器被转发后,收到来自我的Android应用程序的URL。 [英] How to receive a URL from my android app after being forwarded from browser.
问题描述
当用户访问网页的浏览器为我的应用程序,我将其转发到像这样一个URL方案:
<$p$p><$c$c>intent://share?id=123#Intent;package=com.aerstone.mobile;scheme=myapp;launchFlags=268435456;end;我测试过这一点,并能正常工作。现在,当用户从浏览器访问我的应用程序的主页,并已安装的应用程序,该应用程序会自动打开。
有关部分从我的清单是:
&LT;活动机器人:configChanges =keyboardHidden |定位机器人:标签=@字符串/ APP_NAME
机器人:名字=。ui.activity.MainActivity
机器人:launchMode =singleTask&GT;
&LT;! - 添加上面launchMode属性 - &GT;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=android.intent.action.MAIN/&GT;
&LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;
&所述; /意图滤光器&gt;
&LT;! - 添加以下的其他意图过滤器 - &GT;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=android.intent.action.VIEW/&GT;
&LT;类机器人:名字=android.intent.category.DEFAULT/&GT;
&LT;类机器人:名字=android.intent.category.BROWSABLE/&GT;
&lt;数据机器人:计划=的myapp/&GT;
&所述; /意图滤光器&gt;
&LT; /活性GT;
问
应用程序打开后,我怎么能获取网址?我想取 URL的ID = 123
部分。我怎样才能做到这一点?
呼叫 getIntent()的getData()
在的onCreate()
或的getData()
对传入的意图
到 onNewIntent ()
,取决于你的活动是否已经建立或没有。这将返回乌里
重新presenting您的网址。
When a user visits the browser page for my app I am forwarding them to a url scheme like so:
intent://share?id=123#Intent;package=com.aerstone.mobile;scheme=myapp;launchFlags=268435456;end;
I've tested this and this works fine. Now, when the user visits my app's home page from the browser and have the app installed, the app automatically opens up.
Relevant part from my manifest is:
<activity android:configChanges="keyboardHidden|orientation" android:label="@string/app_name"
android:name=".ui.activity.MainActivity"
android:launchMode="singleTask" >
<!-- add the above launchMode attribute -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- add the below additional intent-filter -->
<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="myapp"/>
</intent-filter>
</activity>
Question
After the app opens up, how can I fetch the URL? I want to fetch the id=123
part of the URL. How can I do this?
Call getIntent().getData()
in onCreate()
, or getData()
on the passed-in Intent
to onNewIntent()
, depending on whether your activity was already created or not. That will return the Uri
representing your URL.
这篇关于如何从浏览器被转发后,收到来自我的Android应用程序的URL。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!