'How can I request to open an URL without opening the webbrowser?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
@Override
protected void onPause() {
super.onPause();
mScannerView.stopCamera();
}
@Override
public void handleResult(final Result result) {
//Do anything with result here :D
Log.w("handleResult", result.getText());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Scan result");
builder.setMessage(result.getText());
AlertDialog alertDialog = builder.create();
alertDialog.show();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.getText().toString()));
startActivity(browserIntent);
mScannerView.resumeCameraPreview(this);
}
}
I want to directly open the URL once scanning is done and then reopen the camera. Can anyone please help me ?
Solution 1:[1]
Use a webview load the URL like below:
webView= (WebView) findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
Solution 2:[2]
Try and create your own activity to handle request to open URL .
When I started learning about android and its intents I found it very confusing. But category BROWSABLE in the Manifest does the following.
The target activity can be safely invoked by the browser to display data referenced by a link — for example, an image or an e-mail message.
Read more on: http://developer.android.com/guide/components/intents-filters.html
The two other answers opens the standard web browser and goes to the address specified. If you want a custom browser make the second activity like a web view like this example.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex Lee |
Solution 2 | Glorfindel |