[英]How to open URL at web browser app from MyApp Android
解決了
我想在Android平板電腦上的網絡瀏覽器應用中打開特定的URL。 Web瀏覽器應用程序將從MyApp打開。 MyApp是Webkit Android應用程序,可以通過服務器站點上的jsp或js文件進行編輯。 我沒有MyApp的任何來源。 如何從MyApp在Web瀏覽器中打開URL?
感謝您的理解
[解]
沒有辦法解決這個問題。 只能通過具有適當方法和功能的另一個Android應用程序來控制移動設備中的Android應用程序。 JS或任何其他方式都不能使用Android功能。
我只是不能自己解決這個問題,而是請MyApp的開發人員編輯他的應用程序。
在布局文件中添加一個webview。 使用以下代碼加載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");
在您的應用中使用此代碼。
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.