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 6389605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:25:29+00:00 2026-05-25T03:25:29+00:00

I am new to Android and Java. I have constructed an app using HTML/Javascript

  • 0

I am new to Android and Java. I have constructed an app using HTML/Javascript that is working great.

I now need to create an activity that launches the email client, fills in subject and body, and (the tough part) adds a file attachment. I have not been able to do this from within JavaScript, mailto: will not attach the file.

So I need to accomplish this through Java and execute it from JavaScript. I think this can be done by using addJavaScriptInterface but I cannot find any detailed documentation or examples to go off of.

How could I do this?

Here is what I have so far after reading the documentation:

2nd update to code:

MainActivity.java

public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setIntegerProperty( "splashscreen", R.drawable.splash );
    super.loadUrl("file:///android_asset/www/index.html", 1000);
    WebView mWebView;
    mWebView = (WebView)findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new JavaScriptInterface(), "Android"); 
}
}

JavaScriptInterface.java

public class JavaScriptInterface {

public void doEmail(){
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/html");
    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT,"test text");
    sendIntent.putExtra(Intent.EXTRA_SUBJECT,"test subject");
    sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://test co.html"));
    startActivity(Intent.createChooser(sendIntent, "Send email..."));
    } 
}

Then I would reference the intent through JavaScript by using Android.doEmail().

With the above code I am getting 2 errors in Eclipse
1. The method startActivity(Intent) is undefined for the type – JavaScriptInterface
2. webview cannot be resolved or is not a field – MainActivity

What am I doing wrong?

  • 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-05-25T03:25:30+00:00Added an answer on May 25, 2026 at 3:25 am
    public class MainActivity extends DroidGap {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.setIntegerProperty( "splashscreen", R.drawable.splash );
    
            JavaScriptInterface jsi = new JavaScriptInterface(this, appView);
            appView.addJavascriptInterface(jsi, "Android");
    
            super.loadUrl("file:///android_asset/www/index.html", 1000);
        }
    }
    

    and

    public class JavaScriptInterface {
        private WebView mAppView;
        private DroidGap mGap
    
        public JavaScriptInterface (DroidGap gap, WebView view)
        {
            mAppView = view;
            mGap = gap;
        }
    
        public void doEmail(){
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("text/html");
            sendIntent.putExtra(android.content.Intent.EXTRA_TEXT,"test text");
            sendIntent.putExtra(Intent.EXTRA_SUBJECT,"test subject");
            sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://test co.html"));
            startActivity(Intent.createChooser(sendIntent, "Send email..."));
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Android and Java programming and I've manage to create a simple
I'm new to Eclipse/Java/Android I have already created this project, but I wanted to
I have a custom class that I've written that extends ImageView (for Android Java).
I have a thread in java/Android like this: Handler handler = new Handler() {
I'm pretty new to Android development, but I have some experience with Java and
I have a new web app that is packaged as a WAR as part
New to javascript/jquery and having a hard time with using this or $(this) to
I am new to Android and Java so pardon me if the question sounds
Firstly I am new to android and Java so this is a beginners question.
I have an app that downloads a very large file (over 50MB). Unfortunately I'm

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.