如何使用android粘贴选项

时间:2017-08-31 19:19:40

标签: java android webview

我写了一个Android应用程序,它在webview中加载一个表单,它允许用户扫描条形码并在剪贴板中复制条形码的结果。我想使用android的粘贴功能将其从剪贴板粘贴到webview。当我尝试搜索粘贴时,它只显示我从剪贴板获取数据并将其放在EditText字段中,但这不是我想要的。我想在我的代码中使用库存粘贴功能(类似于longpress字段 - >粘贴)。感谢

public void clickScan(View view){

    final Activity activity = this;
    IntentIntegrator integrator = new IntentIntegrator(activity);
    integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
    integrator.setPrompt("Scan the serial number");
    integrator.setCameraId(0);
    integrator.setBeepEnabled(false);
    integrator.setBarcodeImageEnabled(false);
    integrator.initiateScan();
}

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if(result != null){
        if(result.getContents() ==null){
            Toast.makeText(getApplicationContext(), "Error Scanning the code. Please try again!", Toast.LENGTH_LONG).show();
        }
        else {
            String input =  result.getContents().toString();
            ((ClipboardManager)getSystemService(getApplicationContext().CLIPBOARD_SERVICE)).setText(input);

            Toast.makeText(getApplicationContext(), input,Toast.LENGTH_LONG).show();
        }
    }
    else{
        super.onActivityResult(requestCode, resultCode, data);
    }
}



@Override
protected void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String str = "test";
    WebView webView = (WebView) findViewById(R.id.webView);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("https://docs.google.com/forms/d/e/1FAIpQLSesTx1IBlPZlN5RXzzauJWYxStHOqt7wH_z4lFe0JHQmKm91w/viewform?usp=sf_link");



}

}

1 个答案:

答案 0 :(得分:1)

找到答案的人。 我用过: -

webView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_PASTE));

感谢。