[英]How to open URL at web browser app from MyApp Android
SOLVED 解决了
I want to open specific URL in web browser app on Android tablet. 我想在Android平板电脑上的网络浏览器应用中打开特定的URL。 Web browser app will be opened from MyApp.
Web浏览器应用程序将从MyApp打开。 MyApp is webkit Android app which I can edit via jsp or js files on server site.
MyApp是Webkit Android应用程序,可以通过服务器站点上的jsp或js文件进行编辑。 I don't have any source of MyApp.
我没有MyApp的任何来源。 How can I open URL at web browser from MyApp?
如何从MyApp在Web浏览器中打开URL?
Thanks for your understanding 感谢您的理解
[Solution] [解]
There is no way how to solve this problem. 没有办法解决这个问题。 Android apps in mobile device can be controlled only via another Android app which has a propriet methods and functions.
只能通过具有适当方法和功能的另一个Android应用程序来控制移动设备中的Android应用程序。 JS or any other way cannot use Android functions.
JS或任何其他方式都不能使用Android功能。
I just don't solve this problem by my self, I asked the developer of MyApp to edit his app. 我只是不能自己解决这个问题,而是请MyApp的开发人员编辑他的应用程序。
In the layout file add a webview. 在布局文件中添加一个webview。 Use below code to load the URL
使用以下代码加载URL
WebView web = (WebView) findViewById(R.id.web);
ProgressDialog progressBar = new ProgressDialog(Activity.this);
progressBar.setMessage("Loading");
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.show();
}
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView webView, int errorCode,
String description, String failingUrl) {
super.onReceivedError(webView, errorCode, description, failingUrl);
try {
webView.stopLoading();
} catch (Exception e) {//
}
if (webView.canGoBack()) {
webView.goBack();
}
AlertDialog alertDialog = new AlertDialog.Builder(Activity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Cannot connect to the Server." +
" Check your internet connection and try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
"Try Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
if (progressBar.isShowing()) {
progressBar.dismiss();
}
alertDialog.show();
}
});
web.loadUrl("your_url");
Use this code in your app..
在您的应用中使用此代码。
Intent browserIntent = new
Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(browserIntent);
As for the missing "http://" I'd just do something like this:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.