英文:
open the link in webview Android Studio
问题
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
scannView = findViewById(R.id.scannerView);
codeScanner = new CodeScanner(this, scannView);
resultData = findViewById(R.id.resultsOfQr);
codeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull final Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
resultData.setText(result.getText());
Intent intent = new Intent(getBaseContext(), MainActivity.class);
intent.putExtra("myurl1", result.getText());
startActivity(intent);
}
});
}
});
scannView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
codeScanner.startPreview();
}
});
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanBtn = findViewById(R.id.scanBtn);
MywebView = (WebView) findViewById(R.id.view2);
WebSettings webSettings = MywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
MywebView.loadUrl("https://google.com/APP/");
MywebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("tel:")) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
} else {
return false;
}
}
});
scanBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Scanner.class));
}
});
String myrul = getIntent().getStringExtra("myurl1");
runOnUiThread(new Runnable() {
@Override
public void run() {
MywebView.loadUrl(myrul);
}
});
}
希望这些翻译能够满足您的需求。如果有其他问题,请随时问我。
英文:
hello i have created the webview in mail activity of the android studio and now i am in scanner activity and when the APP scans any QR code having the link it just writs the link but what i want to do is to open the link in the web view already created in mail activity.
let me place my scanner file here
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
scannView = findViewById(R.id.scannerView);
codeScanner = new CodeScanner(this,scannView);
resultData = findViewById(R.id.resultsOfQr);
codeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull final Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
resultData.setText(result.getText());
// Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.getText()));
// startActivity(browserIntent);
Intent intent = new Intent(getBaseContext(), MainActivity.class);
intent.putExtra("myurl1", result.getText());
startActivity(intent);
}
});
}
});
scannView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
codeScanner.startPreview();
}
});
}
scannView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
codeScanner.startPreview();
}
});
}
WEBVIEW in Mailactivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanBtn = findViewById(R.id.scanBtn);
MywebView = (WebView) findViewById(R.id.view2);
WebSettings webSettings = MywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
MywebView.loadUrl("https://google.com/APP/");
MywebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("tel:")) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}else{
return false;
}
}
});
scanBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(),Scanner.class));
}
});
String myrul = getIntent().getStringExtra("myurl1");
runOnUiThread(new Runnable() {
@Override
public void run() {
MywebView.loadUrl(myrul);
}
});
}
Any idea how can i do this, any help is appreciated.
Thankx
答案1
得分: 0
在你的 CodeScanner 回调中加载 WebView
runOnUiThread(new Runnable() {
@Override
public void run() {
resultData.setText(result.getText());
MywebView.loadUrl(result.getText());
}
});
英文:
In you CodeScanner Callback Load the WebView
runOnUiThread(new Runnable() {
@Override
public void run() {
resultData.setText(result.getText());
MywebView.loadUrl(result.getText());
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论