【发布时间】: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。谢谢你。
【问题讨论】: