1
我編寫了一個android應用程序,它在webview中加載了一個表單,它允許用戶掃描條形碼並將條形碼的結果複製到剪貼板中。我想使用android的粘貼功能將它從剪貼板粘貼到webview。當我嘗試搜索粘貼時,它只是顯示我從剪貼板獲取數據並將其放入EditText字段中,但這不是我想要的。我想在我的代碼中使用庫存粘貼功能(類似於longpress字段 - >粘貼)。由於如何使用android粘貼選項
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");
}
}