Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:17:17+00:00 2026-06-07T11:17:17+00:00

I have to send email using webintent in phonegap for android.I am getting error

  • 0

I have to send email using webintent in phonegap for android.I am getting error in the following code.I dont understand how to call the function in script in the index.html file.I am getting json exception.Can anybdy help me to solve this??

WebIntent.java

  public class WebIntent extends Plugin {

        private String onNewIntentCallback = null;
        private static final String TAG = "Webintent";


        public PluginResult execute(String action, JSONArray args, String callbackId) {
            Log.d(TAG, "WebintentPlugin Called");
            try {

                  System.out.println("JSON11"+args);
                if (action.equals("startActivity")) {
                    if (args.length() != 1) {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                    }


                    // Parse the arguments

                    JSONObject obj = args.getJSONObject(0);

                    String type = obj.has("type") ? obj.getString("type") : null;
                    Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null;
                    JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;
                    Map<String, String> extrasMap = new HashMap<String, String>();

                    // Populate the extras if any exist
                    if (extras != null) {
                        JSONArray extraNames = extras.names();
                        for (int i = 0; i < extraNames.length(); i++) {
                            String key = extraNames.getString(i);
                            String value = extras.getString(key);
                            extrasMap.put(key, value);
                        }
                    }

                    startActivity(obj.getString("action"), uri, type, extrasMap);
                    return new PluginResult(PluginResult.Status.OK);

                } else if (action.equals("hasExtra")) {
                    if (args.length() != 1) {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                    }
                    Intent i = ((DroidGap) this.ctx).getIntent();
                    String extraName = args.getString(0);
                    return new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName));

                } else if (action.equals("getExtra")) {
                    if (args.length() != 1) {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                    }
                    Intent i = ((DroidGap) this.ctx).getIntent();
                    String extraName = args.getString(0);
                    if (i.hasExtra(extraName)) {
                        return new PluginResult(PluginResult.Status.OK, i.getStringExtra(extraName));
                    } else {
                        return new PluginResult(PluginResult.Status.ERROR);
                    }
                } else if (action.equals("getUri")) {
                    if (args.length() != 0) {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                    }

                    Intent i = ((DroidGap) this.ctx).getIntent();
                    String uri = i.getDataString();
                    return new PluginResult(PluginResult.Status.OK, uri);
                } else if (action.equals("onNewIntent")) {
                    if (args.length() != 0) {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                    }

                    this.onNewIntentCallback = callbackId;
                    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
                    result.setKeepCallback(true);
                    return result;
                } else if (action.equals("sendBroadcast")) 
                {
                    if (args.length() != 1) {
                        return new PluginResult(PluginResult.Status.INVALID_ACTION);
                    }

                    // Parse the arguments
                    JSONObject obj = args.getJSONObject(0);
                    System.out.println("JSON"+obj);
                    JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;
                    Map<String, String> extrasMap = new HashMap<String, String>();

                    // Populate the extras if any exist
                    if (extras != null) {
                        JSONArray extraNames = extras.names();
                        for (int i = 0; i < extraNames.length(); i++) {
                            String key = extraNames.getString(i);
                            String value = extras.getString(key);
                            extrasMap.put(key, value);
                        }
                    }

                    sendBroadcast(obj.getString("action"), extrasMap);
                    return new PluginResult(PluginResult.Status.OK);
                }
                return new PluginResult(PluginResult.Status.INVALID_ACTION);
            } catch (JSONException e) {
                e.printStackTrace();
                return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
            }
        }

        @Override
        public void onNewIntent(Intent intent) {
            if (this.onNewIntentCallback != null) {
                PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
                result.setKeepCallback(true);
                this.success(result, this.onNewIntentCallback);
            }
        }

        void startActivity(String action, Uri uri, String type, Map<String, String> extras) {
            Intent i = (uri != null ? new Intent(action, uri) : new Intent(action));

            if (type != null && uri != null) {
                i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6
            } else {
                if (type != null) {
                    i.setType(type);
                }
            }

            for (String key : extras.keySet()) {
                String value = extras.get(key);
                // If type is text html, the extra text must sent as HTML
                if (key.equals(Intent.EXTRA_TEXT) && type.equals("text/html")) {
                    i.putExtra(key, Html.fromHtml(value));
                } else if (key.equals(Intent.EXTRA_STREAM)) {
                    // allowes sharing of images as attachments.
                    // value in this case should be a URI of a file
                    i.putExtra(key, Uri.parse(value));
                } else if (key.equals(Intent.EXTRA_EMAIL)) {
                    // allows to add the email address of the receiver
                    i.putExtra(Intent.EXTRA_EMAIL, new String[] {"myemail.com"});
                } else {
                    i.putExtra(key, value);
                }
            }
            this.ctx.startActivity(i);
        }

        void sendBroadcast(String action, Map<String, String> extras) {
            Intent intent = new Intent();
            intent.setAction(action);
            for (String key : extras.keySet()) {
                String value = extras.get(key);
                intent.putExtra(key, value);
            }



            ((DroidGap) this.ctx).sendBroadcast(intent);
        }
    }
webintent.js

    var WebIntent = function() { 

    };

    WebIntent.ACTION_SEND = "android.intent.action.SEND";
    WebIntent.ACTION_VIEW= "android.intent.action.VIEW";
    WebIntent.EXTRA_TEXT = "android.intent.extra.TEXT";
    WebIntent.EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
    WebIntent.EXTRA_STREAM = "android.intent.extra.STREAM";
    WebIntent.EXTRA_EMAIL = "android.intent.extra.EMAIL";

    WebIntent.prototype.startActivity = function(params, success, fail) {
        return cordova.exec(function(args) {
            success(args);
        }, function(args) {
            fail(args);
        }, 'WebIntent', 'startActivity', [params]);
    };

    WebIntent.prototype.hasExtra = function(params, success, fail) {
        return cordova.exec(function(args) {
            success(args);
        }, function(args) {
            fail(args);
        }, 'WebIntent', 'hasExtra', [params]);
    };

    WebIntent.prototype.getUri = function(success, fail) {
        return cordova.exec(function(args) {
            success(args);
        }, function(args) {
            fail(args);
        }, 'WebIntent', 'getUri', []);
    };

    WebIntent.prototype.getExtra = function(params, success, fail) {
        return cordova.exec(function(args) {
            success(args);
        }, function(args) {
            fail(args);
        }, 'WebIntent', 'getExtra', [params]);
    };


    WebIntent.prototype.onNewIntent = function(callback) {
        return cordova.exec(function(args) {
            callback(args);
        }, function(args) {
        }, 'WebIntent', 'onNewIntent', []);
    };

    WebIntent.prototype.sendBroadcast = function(params, success, fail) {
        return cordova.exec(function(args) {
            success(args);
        }, function(args) {
            fail(args);
        }, 'WebIntent', 'sendBroadcast', [params]);
    };



    cordova.addConstructor(function() {
        cordova.addPlugin('WebIntent', new WebIntent());
    });

index.html

<html>
  <head>
    <meta name="viewport" content="target-densitydpi=low-dpi; user-scalable=no" />
    <title>PhoneGap Events Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script> 
     <script type="text/javascript" charset="utf-8" src="webintent.js"></script>

      <script type="text/javascript" charset="utf-8">


         function onBodyLoad()
         {
         document.addEventListener("deviceready",onDeviceReady,false);
        }

   function onDeviceReady() {    
       window.plugins.WebIntent.startActivity('WebIntent', success, fail);

        }
        function success(e) {


        console.log("Success");
        }

        function fail(f) {
             console.log("Failure");
        }





    </script>
  </head>
  <body onload="onBodyLoad();">
    <h2>IMEI v1.5</h2>
    IMEI: <span id="imei"></span><br/>

  </body>
</html>


My error is-

07-10 10:23:12.180: W/System.err(536): org.json.JSONException: Value WebIntent at 0 of type java.lang.String cannot be converted to JSONObject
07-10 10:23:12.200: W/System.err(536):  at org.json.JSON.typeMismatch(JSON.java:100)
07-10 10:23:12.200: W/System.err(536):  at org.json.JSONArray.getJSONObject(JSONArray.java:484)
07-10 10:23:12.230: W/System.err(536):  at com.gsr.imei.WebIntent.execute(WebIntent.java:48)
07-10 10:23:12.240: W/System.err(536):  at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:186)
07-10 10:23:12.240: W/System.err(536):  at java.lang.Thread.run(Thread.java:856)


can anyone help me??Thanks for any help..
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:17:20+00:00Added an answer on June 7, 2026 at 11:17 am
    window.plugins.WebIntent.startActivity('WebIntent', success, fail);
    

    Should be a map object like this:

    window.plugins.WebIntent.startActivity({url: 'url here', type: 'type', extras: {}}, success, fail);
    

    Edit

    Using this function to call the intent

    function sendEmail(to, subject, body) { 
              var extras = {};
              extras[WebIntent.EXTRA_SUBJECT] = subject;
              extras[WebIntent.EXTRA_TEXT] = body;
              window.plugins.webintent.startActivity({
                  url: to,
                  action: WebIntent.ACTION_SEND,
                  type: 'text/plain', 
                  extras: extras 
                }, 
                function() {
                    alert("mail sent");
                }, 
                function() {
                  alert('Failed to send email via Android Intent');
                }
              ); 
        }
    

    It opens up the mail send dialog with all the sent parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following WordPress plugin to send email. http://coffee2code.com/wp-plugins/configure-smtp/ I have done configuration,
I am trying to send an email using c# using the following code. MailMessage
I have code to send email using Exchange Web Services (EWS 1.1 API). There
I have send an email using php mailer class. mail was sending successfully but
Can I send email using jQuery only? I don't have .Net or PHP etc
I have written a perl script to send email using the gmail's smtp server:
I have a scenario where I am to send email using our own SMTP
I have following condition: How do I send email to example@mail.com on submitButton clicklistener
I have working with email option. i can send the Email using the intent
I'm trying to send an email using JavaMail API. I have jdk 1.5 installed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.