1
package com.example.notesexample;

import android.os.Bundle;
import android.app.Activity;

import android.webkit.WebView;

public class MainActivity extends Activity {

    WebView web;
    String str2 = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework"
            + "help help with homework homework assignments elementary school high school middle school"
            + "// --><font color='#60c000' size='4'><strong>Please!</strong></font>"
            + "<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif'  />";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        web = (WebView) findViewById(R.id.webView1);
        web.loadDataWithBaseURL("", str2, "text/html", "UTF-8", "");

    }

}

This is MY code i am display some Text in web view now what i want that i want copy text ontouchselect i have one word and also one paragraph i need to Copy in android webview text Like this Example [https://support.mozilla.org/en-US/kb/how-do-i-copy-and-paste-text-android ] please help me how i will Do this. Thanx I am new in this android Feature.

user2794306
  • 175
  • 3
  • 5
  • 24

1 Answers1

0

From the class that extends WebView:

public void selectAndCopyText() {
try {
    Method m = WebView.class.getMethod("emulateShiftHeld", null);
    m.invoke(this, null);
} catch (Exception e) {
    e.printStackTrace();
    // fallback
    KeyEvent shiftPressEvent = new KeyEvent(0,0,
         KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
    shiftPressEvent.dispatch(this);
}

}

And then you have to use ClipboardManager to watch for new text.

VenuNalla
  • 39
  • 8
  • Please Follow the Link http://developer.android.com/guide/topics/text/copy-paste.html it will be useful – VenuNalla Sep 24 '13 at 12:08
  • ClipData clip = ClipData.newPlainText("simple text","Hello, World!"); i Am confused in this Line what Text i have Put here ? – user2794306 Sep 24 '13 at 12:16