2

我有一个 android 应用程序,当应用程序打开时会转到我的公司网站。我总是让它在 android Google chrome 中打开,每次我调用此代码时,都会在 Google chrome 中创建一个新选项卡。有什么方法可以防止创建新标签。用于打开谷歌浏览器的代码如下

  Intent i = new Intent("android.intent.action.MAIN");
  i.setComponent(ComponentName.unflattenFromString
  ("com.android.chrome/com.android.chrome.Main"));
i.addCategory("android.intent.category.LAUNCHER");
i.setData(Uri.parse("http://google.com"));
startActivity(i);

谢谢你的回答

4

1 回答 1

0

感谢这篇文章,我终于找到了解决方案。这是代码:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class Main extends Activity {

    private WebView mWebview ;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        mWebview  = new WebView(this);

        mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

        final Activity activity = this;

        mWebview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
            }
        });

        mWebview .loadUrl("http://www.google.com");
        setContentView(mWebview );

    }

}
于 2013-09-02T09:25:38.697 回答