谁能指导我如何从android浏览器启动我的android应用程序?


当前回答

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

我们强烈反对人们使用他们自己的方案,除非他们正在定义一个新的全球互联网方案。

其他回答

请注意,如果你的图标从android启动器中消失,当你实现这个功能,那么你必须分割意图过滤器。

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

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

我的应用程序正确启动从http://example.com/someresource/链接从应用程序,如hangouts, gmail等,但不是从chrome浏览器。

为了解决这个问题,让它从CHROME正确启动,你必须像这样设置意图过滤器

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

您的应用程序现在将出现在活动选择器内,每当用户请求http://example.com/someresource/模式从chrome浏览器点击谷歌搜索结果或任何其他网站的链接

example.php:

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

Felix处理深度链接的方法是处理深度链接的典型方法。我还建议您查看这个库来处理深层链接的路由和解析:

https://github.com/airbnb/DeepLinkDispatch

您可以使用注释为特定的深链接URI注册Activity,它将为您提取参数,而不必执行获取路径段、匹配它等通常的繁琐操作。你可以像这样简单地注释和活动:

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

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

我们强烈反对人们使用他们自己的方案,除非他们正在定义一个新的全球互联网方案。