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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:23:47+00:00 2026-05-14T15:23:47+00:00

I believe that it’s possible to call Java methods from (PhoneGap) Javascript. Anyone knows

  • 0

I believe that it’s possible to call Java methods from (PhoneGap) Javascript.

Anyone knows how to do that?? (I know how to do it by changing the source code of PhoneGap, but I’d avoid that)

  • 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-14T15:23:47+00:00Added an answer on May 14, 2026 at 3:23 pm

    I finally made it work.

    • Create a class with methods you want to use:

      public class MyClass {
        private WebView mAppView;
        private DroidGap mGap;
      
        public MyClass(DroidGap gap, WebView view)
        {
          mAppView = view;
          mGap = gap;
        }
      
        public String getTelephoneNumber(){
          TelephonyManager tm = 
            (TelephonyManager) mGap.getSystemService(Context.TELEPHONY_SERVICE);
          String number = tm.getLine1Number();
          return number;
        }
      }
      
    • In your main activity add a Javascript interface for this class:

      public class Main extends DroidGap
      {
          private MyClass mc;
      
          @Override
          public void onCreate(Bundle savedInstanceState)
          {
              super.onCreate(savedInstanceState);
              super.init();
      
              mc = new MyClass(this, appView);
              appView.addJavascriptInterface(mc, "MyCls");
      
              super.loadUrl(getString(R.string.url));
          }
      }
      
    • In Javascript call window.MyCls methods:

      <script>
        $(function(){
          $("#phone").text("My telephone number is: " + 
                  window.MyCls.getTelephoneNumber());
        });
      </script>
      

    Note:

    As mentioned in the comment, for Android version 4.2 and above, add @JavascriptInterface to the method which you want to access from your HTML page. Reference.

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

Sidebar

Related Questions

I used to believe that you should not insert javascript blocks <script language=javascript> <!--
I believe that it's better to code to interfaces instead of implementations. In Java:
I believe that a static function in a source file cannot be called directly
I believe that all the source code in the Android framework could be found
I do not believe that it is possible to completely avoid C-style casts when
I don't believe that you can use the input straight from a content editable
I believe that we are all know that setUp (@Before) will execute before any
From this question one could start to believe that alignment of a union is
I believe that the rallytagpicker is definitely a useful component. However, I do not
I believe that UIView objects can delegate control to views in iOS programming. However,

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.