How do I need to change the HandleResult
code for opening the URL within the application and not in the external browser?
I know that we need something like Webview and the layout file also needs to be in Webview. I hope someone can help me? I tried it but it didn't work.
package com.example.beverly.registrationdatabase;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Patterns;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class ScanCodeActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
ZXingScannerView ScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScannerView = new ZXingScannerView(this);
setContentView(ScannerView);
}
@Override
public void handleResult(Result result) {
if(Patterns.WEB_URL.matcher(result.getText()).matches()) {
// Open URL
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.getText()));
startActivity(browserIntent);
onBackPressed();
}
}
@Override
protected void onPause() {
super.onPause();
ScannerView.stopCamera();
}
@Override
protected void onResume() {
super.onResume();
ScannerView.setResultHandler(this);
ScannerView.startCamera();
}
}
如果您只是尝试从标准网页访问内容,请考虑通过IOUtils.toString()
将内容直接放入字符串中。
Create a new activity with webview in it.
Move your string using intent to a webview Activity and open the url from that webview.
myWebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.loadUrl(String_from_qr_scan);
Do not forget to add Internet permission in manifest. Also if you want webview to navigate further pages from the webpage it will open then you will have to override setWebViewClient() method also.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.