我正在嘗試使用cordova應用程序的webintents,以便能夠將圖像從其他應用程序發送到我的應用程序。無法使用webintents獲取URL或數據
我使用的科爾多瓦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標籤文件,像這樣:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
當我安裝在設備上的應用程序,並嘗試分享圖片我的應用程序在那些應用程序的列表中顯示能夠處理這種共享,並且我也獲得了「App started ...」文本,所以我知道它被調用。
但無論我嘗試什麼樣的圖像,我總是到達getExtra方法的「錯誤」部分,而我的console.log只顯示「錯誤」。調試通過GapDebug直接在設備上完成。
有什麼我失蹤或有任何人想法讓我的應用程序從其他應用程序獲取圖像使用?
在此先感謝!
非常感謝那些信息。太糟糕了,多個圖像/文件似乎不工作,因爲這也是我需要的東西... – Olli