I am trying to implement the phonegap plugin WebIntent in an app that I am making for my work (social housing). I want the app to be able to send emails with attachments (pictures of repairs etc) to our offices so we can see exactly what we need to repair and provide a better service.
I have managed to launch the camera and can take a picture and then on success direct the app to a function that contains the WebIntent plugin. Below is my script:
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);
}
}
As you can see, at the moment I am not trying to pass the imageURI to WebIntent. I just want to get the plugin working with some simple text first. However, whenever I run this function, the plugin returns the 'Failed to send mail' alert without even opening my mail app. Any ideas where I'm going wrong?
My Logcat looks like this:
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
Have I set something up incorrectly? I have added the WebIntent.Java to src/com/borismus, I have added the webintent.js to assets/www, I have added the plugin to my config.xml, and I have referenced the js in my html file. Is there anything I'm missing? I'm using Cordova 2.2.0.
OR is there a better way to pass images to a mail app? I'm aware of EmailComposer for iOS but I'm looking for an Android solution initially. Do any 'share' plugins do this?
Any help would be greatly appreciated.
So after posting this question on the google groups phonegap page I have found the solution. In my case I had put the WebIntent.java in the wrong foler.
I put the WebIntent.java in src/com/borismus.
but it should have been in src/com/borismus/webintent.
For anyone that's interested the following code launches the camera app, and then on success attaches that picture to an email with pre-populated fields using the WebIntent plugin:
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);
}
}
Hope this helps someone out.
Thanks.