【问题标题】:Android Intents with Chrome: "Item not found"带有 Chrome 的 Android 意图:“找不到项目”
【发布时间】:2015-11-14 11:20:10
【问题描述】:

我正在尝试从 Chrome 打开我的应用,但它对我不起作用..

这是官方(非常有限的)文档: Android Intents with Chrome

我发现了一堆类似的问题,但似乎没有一个解决方案对我有用 - 而且,答案有点零散,所以我正在寻找完整的答案并举例说明。一旦我们找到它,我很乐意发布我的完整解决方案:)

这是我现在得到的:

AndroidManifest.xml:

<activity android:name=".ActMain" >
    <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="http" />
        <data android:scheme="https" />
        <data android:scheme="sharedr" />
        <data android:host="pocketr.rejh.nl" />
        <data android:pathPattern="/.*" />
    </intent-filter>
</activity>

Javascript(当用户点击一个元素时它会建立意图链接):

var url = "http://icerrr.rejh.nl/"
var title = "Example"
var intenturl = "intent://sharedr/#Intent;"
    + "package=com.rejh.sharedr;"
    + "S.action=share;"
    + "S.type=url;"
    + "S.title="+ app.helpers.encodeURIComponent(title) +";"
    + "S.url="+ app.helpers.encodeURIComponent(url) +";"
    + "end";
alert(intenturl); // for debugging
try {
    window.location.href=intenturl;
} catch(e) { alert(JSON.stringify(e)); }

我从这个函数中得到以下“链接”:

intent://sharedr/#Intent;package=com.rejh.sharedr;S.action=share;S.type=url;S.title=Example;S.url=http%3A%2F%2Ficerrr.rejh.nl%2F;end

人类可读:

intent://sharedr/#Intent;
    package=com.rejh.sharedr;
    S.action=share;
    S.type=url;
    S.title=Example;
    S.url=http%3A%2F%2Ficerrr.rejh.nl%2F;
end

所以它的工作原理如下:它打开 Play 商店并显示“找不到项目”和一个刷新按钮。所以它打开了一个活动,但不是正确的..

我试图从中触发的网站是 http://pocketr.rejh.nl

帮助?

完整答案

正如下面的 Mattia 所指出的(我自己只是想出了这个问题,但发现答案在等着我……:P)

首先:我忘记在我的意图链接中包含“scheme=sharedr”:

intent://sharedr/#Intent;
    package=com.rejh.sharedr;
    S.action=share;
    S.type=url;
    S.title=Example;
    S.url=http%3A%2F%2Ficerrr.rejh.nl%2F;
end

应该是(注意第二行):

intent://sharedr/#Intent;
    scheme=sharedr;
    package=com.rejh.sharedr;
    S.action=share;
    S.type=url;
    S.title=Example;
    S.url=http%3A%2F%2Ficerrr.rejh.nl%2F;
end

然后,在 android 清单中:

<activity android:name=".ActMain" >
    <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="sharedr" android:host="sharedr" android:path="/"/>
    </intent-filter>
</activity>

其中 'android:scheme="sharedr"' 是 'scheme=sharedr' 部分,而 'android:host="sharedr"' 对应于 'intent://sharedr/'

谢谢!

【问题讨论】:

    标签: android google-chrome android-intent


    【解决方案1】:

    您将sharedr 指定为host,但在AndroidManifest.xml 中配置的hostpocketr.rejh.nl。你也没有指定scheme

    固定的网址是这样的:

    intent://pocketr.rejh.nl/#Intent;scheme=sharedr;package=com.rejh.sharedr;S.action=share;S.type=url;S.title=Example;S.url=http%3A%2F%2Ficerrr.rejh.nl%2F;end
    

    人类可读:

    intent://pocketr.rejh.nl/#Intent;
        scheme=sharedr;
        package=com.rejh.sharedr;
        S.action=share;
        S.type=url;
        S.title=Example;
        S.url=http%3A%2F%2Ficerrr.rejh.nl%2F;
    end
    

    【讨论】:

    • 哦,天哪,我自己才想出来的:P 为什么-o-为什么文档没有“链接”和相应的 androidmanifest 的示例:P 我会更新我的问题在一秒钟内获得完整的解决方案。谢谢!
    猜你喜欢
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多