0

我正在尝试在我为我的工作(社会住房)制作的应用程序中实现 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 解决方案。是否有任何“共享”插件可以做到这一点?

任何帮助将不胜感激。

4

2 回答 2

1

因此,在谷歌群组 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);
        }

    }

希望这可以帮助某人。

谢谢。

于 2012-12-06T13:12:56.837 回答
0

作为您的参考Logcat[ClassNotFoundException: com.borismus.webintent.WebIntent] 我认为您在定义插件时遇到问题config.xml..

有关更多信息,您可以查看https://github.com/InQBarna/WebIntent/blob/master/plugin.xml

于 2014-02-26T06:33:02.613 回答