从android浏览器启动自定义的android应用程序

任何人都可以请指导我如何从Android浏览器启动我的Android应用程序?

<data>元素一起使用<intent-filter> 。 例如,要处理到twitter.com的所有链接,请将其放在您的AndroidManifest.xml <activity>中:

 <intent-filter> <data android:scheme="http" android:host="twitter.com"/> <action android:name="android.intent.action.VIEW" /> </intent-filter> 

然后,当用户点击浏览器中的推特链接时,会询问他们使用什么应用程序来完成操作:浏览器或您的应用程序。

当然,如果你想提供你的网站和你的应用程序之间的紧密集成,你可以定义你自己的scheme:

 <intent-filter> <data android:scheme="my.special.scheme" /> <action android:name="android.intent.action.VIEW" /> </intent-filter> 

然后,在您的networking应用程序,你可以把链接,如:

 <a href="my.special.scheme://other/parameters/here"> 

而当用户点击它,你的应用程序将自动启动(因为它可能是唯一一个可以处理my.special.scheme://types的uris)。 唯一的缺点是,如果用户没有安装应用程序,他们会得到一个讨厌的错误。 我不确定有什么方法可以检查。


编辑:要回答你的问题,你可以使用getIntent().getData() ,它返回一个Uri对象。 然后可以使用Uri.*方法来提取所需的数据。 例如,假设用户点击了http://twitter.com/status/1234的链接:

 Uri data = getIntent().getData(); String scheme = data.getScheme(); // "http" String host = data.getHost(); // "twitter.com" List<String> params = data.getPathSegments(); String first = params.get(0); // "status" String second = params.get(1); // "1234" 

你可以在Activity任何地方执行上面的操作,但是你可能想在onCreate()做到这一点。 您也可以使用params.size()获取Uri中path段的数量。 看看javadoc或android开发者网站的其他Uri方法,你可以用它来提取特定的部分。

请在这里看到我的评论: 在Android浏览器中启动一个链接启动我的应用程序?

我们强烈不鼓励人们使用他们自己的计划,除非他们正在界定一个新的全球互联网计划。

截至2014年1月28日,以上所有答案都不适用于我

我的应用程序正常启动http://example.com/someresource/从环聊,Gmail等应用程序的链接,但不是在Chrome浏览器。;

为了解决这个问题,所以它从CHROME正确启动你必须设置意向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:host="example.com" android:pathPrefix="/someresource/" android:scheme="http" /> <data android:host="www.example.com" android:pathPrefix="/someresource/" android:scheme="http" /> </intent-filter> 

注意pathPrefix元素

当用户通过点击从谷歌search结果或任何其他网站的链接从Chrome浏览器请求http://example.com/someresource/模式时,您的应用程序现在将出现在活动select器内部;

在我的情况下,我不得不为<intent-filter>设置两个类别,然后它的工作:

 <intent-filter> <data android:scheme="my.special.scheme" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> </intent-filter> 

应该还有<category android:name="android.intent.category.BROWSABLE"/>添加到意图filter,使活动从链接中正确识别。

例如,你有下面的东西:

打开您的应用的链接: http : //example.com

您的应用的软件包名称:com.example.mypackage

那么你需要做的下一个:

1)添加一个意图filter到你的活动(可以是你想要的任何活动,更多信息请查阅文档 )。

  <activity android:name=".MainActivity"> <intent-filter android:label="@string/filter_title_view_app_from_web"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Accepts URIs that begin with "http://example.com" --> <data android:host="example.com" android:scheme="http" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

2)创build一个HTML文件来testing链接或使用这个方法。

 <a href="intent://example.com#Intent;scheme=http;package=com.example.mypackage;end">Open your Activity directly (just open your Activity, without a choosing dialog). </a> <a href="http://example.com">Open this link with browser or your programm (by choosing dialog).</a> 

3)使用移动Chrome进行testing

4)就是这样。

而且它没有必要在市场上发布应用程序来testing深层链接=)

另外,如需更多信息,请查看文档和有用的演示文稿 。

以下链接提供了有关从浏览器直接启动应用程序(如果已安装)的信息。 否则,它会直接在Play商店中打开应用程序,以便用户可以无缝下载。

https://developer.chrome.com/multidevice/android/intents

是的,Chromesearch,而不是寻找计划。 如果您想通过URIscheme启动您的应用程序,请在Play商店中使用这个很酷的实用程序应用程序。 它拯救了我的一天:) https://play.google.com/store/apps/details?id=com.naosim.urlschemesender

请注意,如果您的图标在实现此function时从android启动器中消失,则必须拆分intent-filter。

  <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </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="your-own-uri" /> </intent-filter> </activity> 

菲利克斯处理深层链接的方法是处理深层链接的典型方法。 我也build议检查这个库来处理你的深层链接的路由和parsing:

https://github.com/airbnb/DeepLinkDispatch

你可以使用注解来注册一个特定的深层链接的URI的活动,它会为你提取出参数,而不必像通常那样得到path段,匹配它等等。你可以简单地注释和这样的活动:

 @DeepLink("somePath/{someParameter1}/{someParameter2}") public class MainActivity extends Activity { ... } 

使用example.php:

 <?php if(!isset($_GET['redirecting'])){ $app_link = 'YourApp://profile/blabla'; $full_link = 'http://yoursite.com/profile/bla'; ?> <iframe src="example.php?redirecting=ok&firstLINK=<?php echo urlencode($app_link);?>" style="display:none;" scrolling="no" frameborder="0"></iframe> <iframe src="example.php?redirecting=ok&secondLINK=<?php echo urlencode($full_link);?>" style="display:none;" scrolling="no" frameborder="0"></iframe> <?php } else { ?> <script type="text/javascript"> self.window.location = '<?php echo $_GET['firstLINK'];?>'; window.parent.location.href = '<?php echo $_GET['secondLINK'];?>'; </script> <?php } 

嘿,我得到了解决scheme。 我没有把类别设置为“默认”。 此外,我正在使用主要活动的意图数据。 现在我正在使用意向数据的不同活动。 谢谢您的帮助。 🙂

你需要添加一个伪主机名到CALLBACK_URL'app://'作为URL没有意义,并且不能被parsing。