当点击自定义URI时,启动 "我的活动 "的意图过滤器。

问题描述 投票:23回答:7

我正在尝试让一个URI被注册,以打开我的应用程序。像 PatternRepository 在黑莓手机和 CFBundleURLNameCFBundleURLSchemes 在iPhone上。如何在安卓系统上达到同样的效果?

系统会通过以下链接发送邮件。 myapp://myapp.mycompany.com/index/customerId/12345. 我们的想法是,用户应该能够点击链接,打开应用程序中的客户活动。

我已经尝试了许多来自其他SO帖子的建议,但我无法让操作系统识别该模式并打开我的应用程序。

在Gmail应用中,它看起来像这样:myapp:/。myapp.mycompany.comindexcustomerId12345)。. 它承认并强调了 myapp.mycompany.com/index/customerId/12345 部分的链接,并在浏览器中打开它。浏览器中打开。myapp:// 部分不 联动.

标准邮件应用程序将整个链接视为纯文本。

我在这里遗漏了什么?

PS: 我已经看了 如何在安卓上实现我自己的URI方案?如何注册一些URL命名空间(myapp:/app.start),以便在Android操作系统中通过在浏览器中调用URL来访问你的程序?

歧。

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="2"
    android:versionName="0.0.8" 
    package="com.mycompany.myapp.client.android">

    <uses-sdk 
        android:minSdkVersion="7" 
        android:targetSdkVersion="7"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application 
        android:label="@string/app_name" 
        android:name="myappApplication" 
        android:icon="@drawable/ic_icon_myapp" 
        android:debuggable="true">

        <activity 
            android:label="My App" 
            android:name=".gui.activity.LoginActivity" 
            label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <activity android:name=".gui.activity.CustomerDetailActivity" > 
            <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>

        <activity android:name=".gui.activity.CustomerDetailActivity"/>
        <activity android:name=".gui.activity.CustomerImageViewerActivity" />
        <activity android:name=".gui.activity.CustomerListActivity" android:configChanges="orientation|keyboardHidden"/>
        <activity android:name=".gui.activity.HomeActivity" android:configChanges="orientation|keyboardHidden"/>
        <activity android:name=".gui.activity.AboutActivity" android:configChanges="orientation|keyboardHidden"/>
        <activity android:name=".gui.activity.AccountActivity" android:configChanges="orientation|keyboardHidden" />  
    </application>
</manifest>
android uri android-manifest android-intent
7个回答
13
投票

最后的解决方案是一个黑客的工作方法,以覆盖所有的基础。现在邮件中还包含了一个扩展名的附件,该附件是用应用注册打开的。

Manifest。

        <activity android:name=".gui.activity.CustomerDetailActivity" > 
        <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="https"
                 android:host="myapp.mycompany.com" /> 
        </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"
                 android:host="myapp.mycompany.com" /> 
        </intent-filter> 
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.EDIT" />
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:mimeType="application/myapp" />
        </intent-filter>
    </activity>

6
投票

当我使用谷歌日历的OAuth时,我必须在我想要接收回调的活动中添加这个过滤器。

<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:scheme="yourapp" android:host="goog"></data>
</intent-filter>

浏览器调用的时候 yourapp://goog URL,它将返回到我的活动。


4
投票

你可以通过使用标准的HTTP URL和302重定向来解决GMail不链接非标准协议的问题。 你可以在你的网站的web服务器或应用程序服务器上设置它,或者为了快速和肮脏的测试,你可以使用一个URL缩短器,如 http:/bit.ly.


1
投票

这是我的解决方案。谢谢 @DanO

<intent-filter>
        <data android:scheme="yourcustomname"/>
        <data android:host="*"/>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
  </intent-filter>

0
投票

你有没有干脆在你的intent-filter中添加一个类别。

<category android:name="android.intent.category.BROWSABLE" />

0
投票

你可以试试用HTML发送邮件,然后用一个 <a> 标签来创建URL。我不认为有办法改变Gmail或Mail解析文本的方式,因为他们可能会使用 Linkify 类。

另一个选择是使用 http:/,然后解析一个特定的自定义子域,这将为你的用户提供在浏览器或应用程序中打开的选项。


0
投票

我刚刚也遇到了这个问题,但是对于标准的http:scheme urls。 Gmail似乎没有在Intent中添加任何类别。 现在我检查了BROWSABLE,但我也检查了 !intent.hasCategories(),并允许它也通过。

© www.soinside.com 2019 - 2024. All rights reserved.