我正在尝试在我正在为我的工作(社交住房)制作的应用中实施phonegap插件WebIntent。我希望该应用能够将带有附件的电子邮件(维修图片等)发送到我们的办公室,以便我们能够准确了解我们需要维修的内容并提供更好的服务。
我已设法启动相机并可拍照,然后成功将应用程序指向包含WebIntent插件的功能。以下是我的剧本:
function camera()
{
navigator.camera.getPicture(sendEmail, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI });
function sendEmail(to, subject, body) {
var extras = {};
extras[WebIntent.EXTRA_SUBJECT] = "Test";
extras[WebIntent.EXTRA_TEXT] = "Test";
window.plugins.webintent.startActivity({
url: "johnsmith@gmail.com",
action: WebIntent.ACTION_SEND,
type: 'image/jpeg',
extras: extras
},
function() {
alert("mail sent");
},
function() {
alert('Failed to send email');
}
);
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
正如您所看到的,目前我并没有尝试将imageURI传递给WebIntent。我只想先让插件使用一些简单的文本。但是,每当我运行此功能时,插件都会返回“无法发送邮件”警报,甚至无需打开我的邮件应用程序。我出错的任何想法?
我的Logcat看起来像这样:
12-04 21:56:28.242: I/CordovaLog(25195): Changing log level to DEBUG(3)
12-04 21:56:28.252: I/CordovaLog(25195): Found preference for useBrowserHistory=true
12-04 21:56:28.252: D/CordovaLog(25195): Found preference for useBrowserHistory=true
12-04 21:56:28.252: I/CordovaLog(25195): Found preference for exit-on-suspend=false
12-04 21:56:28.252: D/CordovaLog(25195): Found preference for exit-on-suspend=false
12-04 21:56:28.292: D/JsMessageQueue(25195): Set native->JS mode to 2
12-04 21:56:28.322: D/DroidGap(25195): DroidGap.init()
12-04 21:56:28.622: D/HardwareRenderer(25195): Disabling v-sync
12-04 21:56:28.622: D/CordovaWebView(25195): DroidGap.loadUrl(file:///android_asset/www/index.html, 10000)
12-04 21:56:28.622: D/DroidGap(25195): onMessage(splashscreen,show)
12-04 21:56:28.622: D/CordovaWebView(25195): >>> loadUrl(file:///android_asset/www/index.html)
12-04 21:56:28.622: D/PluginManager(25195): init()
12-04 21:56:28.652: D/CordovaWebView(25195): >>> loadUrlNow()
12-04 21:56:28.652: D/DroidGap(25195): Resuming the App
12-04 21:56:28.662: D/HardwareRenderer(25195): Disabling v-sync
12-04 21:56:28.662: D/DroidGap(25195): Paused the application!
12-04 21:56:28.662: D/CordovaWebView(25195): Handle the pause
12-04 21:56:28.722: D/libEGL(25195): loaded /system/lib/egl/libGLES_android.so
12-04 21:56:28.732: D/libEGL(25195): loaded /system/lib/egl/libEGL_adreno200.so
12-04 21:56:28.752: D/libEGL(25195): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
12-04 21:56:28.752: D/libEGL(25195): loaded /system/lib/egl/libGLESv2_adreno200.so
12-04 21:56:28.882: D/OpenGLRenderer(25195): Enabling debug mode 0
12-04 21:56:28.882: W/Adreno200-EGLSUB(25195): SetSwapInterval() interval: 0 not set
12-04 21:56:28.902: W/Adreno200-EGLSUB(25195): SetSwapInterval() interval: 0 not set
12-04 21:56:29.052: D/DroidGap(25195): onMessage(onPageStarted,file:///android_asset/www/index.html)
12-04 21:56:29.332: D/CordovaLog(25195): exception firing pause event from native
12-04 21:56:29.332: D/CordovaLog(25195): null: Line 1 : exception firing pause event from native
12-04 21:56:29.332: I/Web Console(25195): exception firing pause event from native at null:1
12-04 21:56:32.142: D/Cordova(25195): onPageFinished(file:///android_asset/www/index.html)
12-04 21:56:32.142: D/DroidGap(25195): onMessage(onNativeReady,null)
12-04 21:56:32.142: D/DroidGap(25195): onMessage(onPageFinished,file:///android_asset/www/index.html)
12-04 21:56:32.242: I/SqliteDatabaseCpp(25195): sqlite returned: error code = 14, msg = cannot open file at line 27699 of [8609a15dfa], db=/data/data/com.saffronhousingmobileapp/databases/webview.db
12-04 21:56:32.242: I/SqliteDatabaseCpp(25195): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27699 - "" errno=2 path=/CachedGeoposition.db, db=/data/data/com.saffronhousingmobileapp/databases/webview.db
12-04 21:56:33.562: D/DroidGap(25195): onMessage(networkconnection,wifi)
12-04 21:56:33.612: D/DroidGap(25195): onMessage(splashscreen,hide)
12-04 21:56:33.622: D/DroidGap(25195): onMessage(spinner,stop)
12-04 21:56:34.192: D/DroidGap(25195): onMessage(spinner,stop)
12-04 21:58:47.542: D/SoftKeyboardDetect(25195): Ignore this event
12-04 21:58:48.242: D/DroidGap(25195): Resuming the App
12-04 21:58:52.032: D/Cordova(25195): onPageFinished(file:///android_asset/www/index.html#page4)
12-04 21:58:52.032: D/DroidGap(25195): onMessage(onNativeReady,null)
12-04 21:58:52.032: D/DroidGap(25195): onMessage(onPageFinished,file:///android_asset/www/index.html#page4)
12-04 21:58:55.182: D/DroidGap(25195): Paused the application!
12-04 21:58:55.182: D/CordovaWebView(25195): Handle the pause
12-04 21:58:55.582: D/OpenGLRenderer(25195): Flushing caches (mode 1)
12-04 21:58:55.662: D/OpenGLRenderer(25195): Flushing caches (mode 0)
12-04 21:59:04.372: D/dalvikvm(25195): GC_FOR_ALLOC freed 1484K, 48% free 4368K/8323K, paused 18ms
12-04 21:59:05.252: I/dalvikvm-heap(25195): Grow heap (frag case) to 31.703MB for 20155408-byte allocation
12-04 21:59:05.252: W/CursorWrapperInner(25195): Cursor finalized without prior close()
12-04 21:59:05.292: D/dalvikvm(25195): GC_CONCURRENT freed 9K, 15% free 24042K/28039K, paused 1ms+3ms
12-04 21:59:10.572: D/dalvikvm(25195): GC_EXPLICIT freed 19734K, 85% free 4321K/28039K, paused 2ms+3ms
12-04 21:59:10.572: W/CursorWrapperInner(25195): Cursor finalized without prior close()
12-04 21:59:10.572: D/DroidGap(25195): Resuming the App
12-04 21:59:10.612: W/Adreno200-EGLSUB(25195): SetSwapInterval() interval: 0 not set
12-04 21:59:10.662: W/System.err(25195): java.lang.ClassNotFoundException: com.borismus.webintent.WebIntent
12-04 21:59:10.662: W/System.err(25195): at java.lang.Class.classForName(Native Method)
12-04 21:59:10.662: W/System.err(25195): at java.lang.Class.forName(Class.java:217)
12-04 21:59:10.662: W/System.err(25195): at java.lang.Class.forName(Class.java:172)
12-04 21:59:10.662: W/System.err(25195): at org.apache.cordova.api.PluginEntry.getClassByName(PluginEntry.java:102)
12-04 21:59:10.662: W/System.err(25195): at org.apache.cordova.api.PluginEntry.createPlugin(PluginEntry.java:78)
12-04 21:59:10.662: W/System.err(25195): at org.apache.cordova.api.PluginManager.getPlugin(PluginManager.java:258)
12-04 21:59:10.662: W/System.err(25195): at org.apache.cordova.api.PluginManager.exec(PluginManager.java:216)
12-04 21:59:10.662: W/System.err(25195): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:43)
12-04 21:59:10.662: W/System.err(25195): at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
12-04 21:59:10.662: W/System.err(25195): at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
12-04 21:59:10.662: W/System.err(25195): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1370)
12-04 21:59:10.662: W/System.err(25195): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 21:59:10.672: W/System.err(25195): at android.os.Looper.loop(Looper.java:137)
12-04 21:59:10.672: W/System.err(25195): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:789)
12-04 21:59:10.672: W/System.err(25195): at java.lang.Thread.run(Thread.java:856)
12-04 21:59:10.672: W/System.err(25195): Caused by: java.lang.NoClassDefFoundError: com/borismus/webintent/WebIntent
12-04 21:59:10.672: W/System.err(25195): ... 15 more
12-04 21:59:10.672: W/System.err(25195): Caused by: java.lang.ClassNotFoundException: com.borismus.webintent.WebIntent
12-04 21:59:10.672: W/System.err(25195): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-04 21:59:10.672: W/System.err(25195): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-04 21:59:10.672: W/System.err(25195): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-04 21:59:10.682: W/System.err(25195): ... 15 more
12-04 21:59:10.682: I/System.out(25195): Error adding plugin com.borismus.webintent.WebIntent.
12-04 21:59:10.762: D/HardwareRenderer(25195): Disabling v-sync
12-04 21:59:10.812: W/Adreno200-EGLSUB(25195): SetSwapInterval() interval: 0 not set
我是否设置错误?我已将WebIntent.Java添加到src / com / borismus,我已将webintent.js添加到assets / www,我已将插件添加到我的config.xml中,并且我已在我的html文件中引用了js。有什么我想念的吗?我正在使用Cordova 2.2.0。
是否有更好的方法将图像传递给邮件应用程序?我知道适用于iOS的EmailComposer,但我最初正在寻找Android解决方案。任何“共享”插件都可以这样做吗?
非常感谢任何帮助。
答案 0 :(得分:1)
因此,在google群组phonegap页面上发布此问题后,我找到了解决方案。在我的情况下,我把WebIntent.java放在错误的填充程序中。
我将WebIntent.java放在src / com / borismus中。
但它应该在src / com / borismus / webintent中。
对于任何感兴趣的人,以下代码启动相机应用程序,然后成功将该图片附加到使用WebIntent插件预填充字段的电子邮件中:
function camera()
{
navigator.camera.getPicture(sendEmail, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI });
function sendEmail(imageURI) {
var extras = {};
extras[WebIntent.EXTRA_SUBJECT] = "Please type your name and address here.";
extras[WebIntent.EXTRA_TEXT] = "Please type your query here.";
extras[WebIntent.EXTRA_STREAM] = imageURI;
window.plugins.webintent.startActivity({
url: "johnsmith@gmail.com",
action: WebIntent.ACTION_SEND,
type: 'image/jpeg',
extras: extras
},
function() {
alert("Mail sent");
},
function() {
alert('Failed to send email');
}
);
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
希望这可以帮助别人。
感谢。
答案 1 :(得分:0)
参考您的Logcat
,[ClassNotFoundException: com.borismus.webintent.WebIntent]
我认为你在config.xml
..
有关详情,请查看https://github.com/InQBarna/WebIntent/blob/master/plugin.xml