2016-03-11 26 views
0

解决如何从MyApp的Android版中开启网页在浏览应用程序URL

我想在Android平板电脑的网页浏览器应用程序中打开特定的URL。 Web浏览器应用程序将从MyApp打开。 MyApp是webkit Android应用程序,我可以通过服务器站点上的jsp或js文件进行编辑。我没有任何MyApp的来源。 如何从MyApp在Web浏览器中打开URL?

感谢您的理解

[解决方法]

有没有办法如何解决这个问题。移动设备中的Android应用只能通过另一个拥有专有方法和功能的Android应用进行控制。 JS或任何其他方式不能使用Android功能。

我只是没有自己解决这个问题,我问MyApp的开发者编辑他的应用程序。

+0

你能发布一些代码吗? – user3641702

回答

1

在布局文件中添加一个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"); 
+0

我无法编辑MyApp。我没有MyApp的源代码。我只能使用JS。所以有可能从JS函数调用intent? – Stepan

0

使用此代码在您的应用程序..

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; 
+0

我无法编辑MyApp。我没有MyApp的源代码。我只能使用JS。所以有可能从JS函数调用intent? – Stepan

相关问题