【问题标题】:PhoneGAP, Cordova : Modifying Android project to load external URLPhoneGAP,Cordova:修改 Android 项目以加载外部 URL
【发布时间】:2016-11-08 18:13:56
【问题描述】:

我正在尝试使用 Cordova 和 phonegap。从可用的教程中,我能够从命令行创建一个 cordova 应用程序,并通过下面提到的命令向它添加 android 平台。然后我在 Android Studio 中导入了 android 项目。由于 phonegap 需要 html、css 内容,我修改了 index.html 以加载外部 URL,但它不起作用。我究竟做错了什么?如何让应用程序加载外部 URL?正如我所看到的,还有许多其他建议,但没有一个拥有我所做的数据。谢谢。

另外,当我在 config.xml 中将文件从 index.html 更改为 URL 时,它打开了一个 chrome 实例,而不是在应用程序中打开它。

命令:

cordova create hello com.example.hello HelloWorld
cordova platform add android --save
cordova build

MainActivity.java:

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // enable Cordova apps to be started in the background
        Bundle extras = getIntent().getExtras();
        if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
            moveTaskToBack(true);
        }

        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}

在 index.html 中添加了以下行,但这也不起作用:

    <script>window.location.href="URL_I_AM_TRYING_TO_OPEN"</script>

config.xml:

// Trying to open google.com
  <content src="http://www.google.com" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-intent href="market:*" />
    <preference name="loglevel" value="DEBUG" />

如何在应用程序本身中加载外部 URL。谢谢你。

【问题讨论】:

    标签: java android cordova


    【解决方案1】:

    allow-intent 标记的作用是打开您放在可以处理该方案的系统应用程序上的 href 属性上的方案/url,所以现在您的 &lt;allow-intent href="http://*/*" /&gt; 正在使用 google url 打开 chrome。

    你需要的标签不是allow-intent,而是allow-navigation

    添加 &lt;allow-navigation href="http://www.google.com" /&gt; 仅允许在您的应用内导航到 google.com,其余网址在 chrome 中打开,或添加 &lt;allow-navigation href="*" /&gt; 以允许导航到您应用内的任何网站

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      相关资源
      最近更新 更多