【发布时间】:2015-07-10 19:06:11
【问题描述】:
我正在尝试将 webintents 与 cordova 应用程序一起使用,以便能够将图像从另一个应用程序发送到我的应用程序。
我正在使用 cordova 5.1.1 并将以下插件添加到我的 android 平台项目中:
com.virtualartifacts.webintent 1.0.0 "WebIntent"
cordova-plugin-camera 1.1.0 "Camera"
cordova-plugin-console 1.0.0 "Console"
cordova-plugin-device 1.0.0 "Device"
cordova-plugin-file 2.0.0 "File"
cordova-plugin-file-transfer 1.1.0 "File Transfer"
cordova-plugin-whitelist 1.0.0 "Whitelist"
项目的 index.html 文件如下所示:
<!DOCTYPE html>
<html>
<head>
<title>WebIntent Test</title>
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<script src="cordova.js"></script>
<script src="js/webintent.js"></script>
<script>
function init() {
document.addEventListener("deviceready",deviceReady,false);
}
function deviceReady() {
console.log("App started. Device ready");
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_STREAM,
function(data) {
console.log(data); // which never gets called
}, function(e) {
console.log(e);
// I simply get the message "Error"
});
}
</script>
</head>
<body onload="init()">
<h1>Demo WebIntent</h1>
</body>
</html>
所以这里没有什么特别的。 在网上搜索了一段时间后,我发现了一些关于 webintent 插件有问题的信息(如提到的here on SO。所以我找到了修补版本并仔细检查了正确的代码是否在 WebIntent.java 文件中。
我还在 AndroidManifest.xml 文件中添加了意图过滤器标签,如下所示:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
当我在设备上安装应用程序并尝试共享图像时,我的应用程序显示在能够处理此共享的应用程序列表中,并且我还收到“应用程序启动...”文本,所以我知道它会被调用。
但无论我尝试什么样的图像,我总是会到达 getExtra 方法的“错误”部分,而我的 console.log 只显示“错误”。通过 GapDebug 直接在设备上进行调试。
我有什么遗漏的吗,或者有人知道如何让我的应用从其他应用中获取图像以供使用吗?
提前致谢!
【问题讨论】:
标签: android cordova cordova-plugins webintents