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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:45:45+00:00 2026-06-12T06:45:45+00:00

I need to programatically trigger text selection mode in a WebView, but the code

  • 0

I need to programatically trigger text selection mode in a WebView, but the code I have used does not work on Jelly Bean?

I have been using the following code but it no longer works on Android 4.1 (Jelly Bean) because WebView.selectText, emulateShiftHeld, and the key dispatch are no longer supported on Jelly Bean.

Following code that works on all versions up to ICS is based on: How to enable the default highlight menus in android webview?

public void selectAndCopyText() {
    try {
        // ICS
            WebView.class.getMethod("selectText").invoke(this);
        } catch (Exception e1) {
        try {
            Method m = WebView.class.getMethod("emulateShiftHeld", (Class[])null);
            m.invoke(this, (Object[])null);
        } catch (Exception e2) {
            // fallback
            KeyEvent shiftPressEvent = new KeyEvent(0,0,
                     KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
            shiftPressEvent.dispatch(this);
        }
    }
}

How do I implement similar functionality that works on Jelly Bean?

  • 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-12T06:45:46+00:00Added an answer on June 12, 2026 at 6:45 am

    I have listed a potential solution in the comments here: How to enable the default highlight menus in android webview?

    Here is the content of the potential solution:
    After analyzing android.webkit.WebViewClassic I have had some success with the following:

    KeyEvent enterEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_ENTER,0,0);
    enterEvent.dispatch(this); 
    

    I thought more might be required as I needed to scroll down the WebView a little before the above worked when using an emulator, but after testing on a real JellyBean device the above seems to work fine.

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

Sidebar

Related Questions

I have a WPF app in which I need to programatically manipulate at runtime.
I have a RichTextBox and I add some texts programatically. I need to display
I need to trigger the hover state of a Flex button programatically, so that
I need to programmatically trigger the change event. This I can usually do, but
I need to programatically determine if my app is running in development or not,
I need to programatically send a form over POST. I have 4 fields, one
I have a situation where I need to programatically select an option within a
I need to programatically append to a multi-page TIFF or PDF a new image.
I need to programatically encrypt a directory of files, like in a .zip or
I am in a need of programatically convert an Word-XML file into a RTF

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.