0

I am working on Android 4.0.3 . I am trying to select the text from the WebView and saving it as a string . I have tried this Code:

public void SelectText(){  
try{  
           KeyEvent shiftPressEvent =   
           new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,       
           KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);  
           shiftPressEvent.dispatch(mWebView);  

}catch(Exception e){  
  throw new AssertionError(e);  
}  

But it doesnot work . In Android 4 there is already an inbuilt menu for selecting text but how this menu could be overridden ??

Renjith
  • 5,783
  • 9
  • 31
  • 42
Navdroid
  • 1,541
  • 3
  • 25
  • 52

1 Answers1

2

This solution uses a javascript interface to pass touches to the page and effectively cut Android's native selection out of the equation. This has been tested from 2.2 to 4.0.3.

Look at this Github Project .

Chirag
  • 56,621
  • 29
  • 151
  • 198