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

  • Home
  • SEARCH
  • 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 8143061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:59:43+00:00 2026-06-06T12:59:43+00:00

Here’s what I want in my android app. I want a button in webview

  • 0

Here’s what I want in my android app.

I want a button in webview call a method in my java. This method should call facebook sdk’s authorize() function and do SSO/Dialog way of authentication. The access token and the expire token are returned back to webview when i call a javascript method in webview.

Here’s what I’ve created already.

In my onCreate() of activity I’m initializing the webview.

mFB = new Facebook(APP_ID);
wv = (WebView) findViewById(R.id.web_view);
wv.getSettings().setJavaScriptEnabled(true);
wv.addJavascriptInterface(new JSInterface(this), "JAVA");
wv.loadUrl("file:///android_asset/test.html");

The test.html in my assets folder is this –

<script type="text/javascript">
        function authorizeFacebook() {
           JAVA.authorizeFacebook();    
        }

        function showData(token, expire) {
            document.getElementById('result').innerHTML = token + " >>>> " + expire;
        }
</script>

The interfacing between JS and Java are working fine. That I’m sure of. My JSInterface is –

public class JSInterface {
    public Context mContext;

    JSInterface(Context c) {
        mContext = c;
    }

    public void authorizeFacebook() {   
        Log.e("FB", "authorizeFacebook() interface called");
        authorizeFacebookSSO();
    }
}

    

public void authorizeFacebookSSO() {
    mFB.authorize(FBCMTestActivity.this, new DialogListener() {

    @Override
    public void onFacebookError(FacebookError e) {
        Log.e("FBAUTH", "FB failed + " + e.getErrorCode());
        Toast.makeText(getApplicationContext(), "FBFAIL:" + e.getMessage(), Toast.LENGTH_LONG).show();
    }

    @Override
    public void onError(DialogError e) {
        Log.e("FBAUTH", "FB failed + " + e.getMessage());
        Toast.makeText(getApplicationContext(), "FBFAIL:" + e.getMessage(), Toast.LENGTH_LONG).show();
    }

    @Override
    public void onComplete(Bundle values) {
        Log.e("FBAUTH", "SUCCESS");
        Log.e("FBAUTH:", mFB.getAccessToken() + " " + mFB.getAccessExpires());
        wv.loadUrl("javascript:showData( '" + mFB.getAccessToken() + "' , '" + mFB.getAccessExpires()  + "');");
    }

    @Override
    public void onCancel() {
    }
});
}

When I have the facebook app, this works great.

But when there is no facebook app, it should ideally show a Dialog with webview. But it fails and stops at – ‘Loading…’ screen.

enter image description here

It just stays there and doesn’t even crash. There are no logs. After a while I get to either force close it or wait for it. Has anyone faced this issue before?

UPDATE

My onActivityResultCode() –

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mFB.authorizeCallback(requestCode, resultCode, data);
    }
  • 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-06T12:59:45+00:00Added an answer on June 6, 2026 at 12:59 pm

    Well I figured this out myself.

    When I call a Java function from WebView’s javascript, the function runs in webview’s thread. So making it run on UI thread fixed everything for me 🙂

    Hope that helps others.

    Here’s the only change that I’ve made in the above code.

    public class JSInterface {
        public Context mContext;
    
        JSInterface(Context c) {
            mContext = c;
        }
    
        public void authorizeFacebook() {   
    
           runOnUiThread(new Runnable() {
    
               @Override
               public void run() {
                    try {
                            authorizeFacebookSSO();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });           
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the method. I want to know if I am violating any best practices
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is a complete example. I want to forbid using A::set from objects casted
Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here's a Clone() implementation for my class: MyClass^ Clone(){ return gcnew MyClass(this->member1, this->member2); }
Here is my persistence.xml : <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd version=1.0>
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here's my Manifest: <?xml version=1.0 encoding=utf-8?> <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.mappp.mobile android:versionCode=1 android:versionName=1.0 > <supports-screens android:largeScreens=true
Here's what I'm doing. I want to upload multipart file via Ajax to my

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.