2

Phonegap 2.9 Android 应用程序出现以下情况:我声明了一个自定义意图,以便可以从网站打开该应用程序。在应用程序中,我使用表单调用我控制的外部站点。在外部站点的页面上有一个按钮,它使用自定义意图 URL 返回应用程序。

此构造适用于应用程序的 iOS 版本,也使用 Phonegap。

但是,对于 Android 版本,Android 的弹出窗口说它无法识别自定义 URL/意图。当我打开浏览器并导航到同一个外部站点并使用自定义意图 URL 按下后退按钮时,应用程序就会启动。

在 stackoverflow 和互联网上搜索了几个小时后,我仍然无法弄清楚为什么它没有像预期的那样工作。

也许很高兴知道该应用程序和外部站点都在使用 jQuery Mobile。使用从应用程序打开外部站点

navigator.app.loadUrl('https://site.external/');

该页面位于 HTTPS / SSL 位置,这有什么区别吗?

清单如下所示:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
      package="com.test.app" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

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

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

    <application android:icon="@drawable/icon" android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:debuggable="true"
        android:allowBackup="false">
        <activity android:name="AppName" android:label="@string/app_name"
                android:theme="@android:style/Theme.Black.NoTitleBar"
                android:screenOrientation="portrait"
                android:launchMode="singleTop"
                android:exported="true"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <data android:scheme="customurl" />
                <action android:name="android.intent.action.VIEW" />    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
        <activity
            android:name="org.apache.cordova.DroidGap" 
            android:label="@string/app_name" 
            android:configChanges="orientation|keyboardHidden"> 
            <intent-filter></intent-filter> 
    </activity>
    </application>    
</manifest> 

外部页面中的代码使用 javascript 来防止 Google 自动搜索可能出现的问题:

window.location = 'customurl://back/';

使用自定义意图按下按钮时收到的错误:

Application Error
The protocol is not supported. (customurl://back/)

那么,如何让从应用程序访问的外部网站重新启动应用程序,以便用户回到应用程序?在搜索了几个小时后,我能想到的唯一可能性是在用户导航到外部站点时关闭应用程序。

4

1 回答 1

1

我认为您可能还需要在意图过滤器中设置主机:

<data android:scheme="customurl" />
<data android:host="somewebsite.com" />

你能检查一下这是否有影响吗?

于 2013-09-02T14:34:24.780 回答