如何在android中打开url
请先阅读我的问题 我想在我的应用程序中而不是在手机浏览器中打开URL 你可以在Facebook或Twitter上看到他们如何在自己的应用程序中打开链接 这将重定向到我手机的浏览器如何在android中打开url,android,Android,请先阅读我的问题 我想在我的应用程序中而不是在手机浏览器中打开URL 你可以在Facebook或Twitter上看到他们如何在自己的应用程序中打开链接 这将重定向到我手机的浏览器 Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(browserIntent); 但我想打开类似Facebook应用程序的URL 这种视图是否有特定的API。
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
但我想打开类似Facebook应用程序的URL
这种视图是否有特定的API。您可以在新活动中使用webview打开url 我想你想使用,请查看链接 下面是网站上的基本示例
// Use a CustomTabsIntent.Builder to configure CustomTabsIntent.
// Once ready, call CustomTabsIntent.Builder.build() to create a CustomTabsIntent
// and launch the desired Url with CustomTabsIntent.launchUrl()
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
以下代码将帮助您在应用程序中打开url:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class AppWebViewActivity extends Activity {
private WebView mWebview;
private String mWebViewUrl;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebViewUrl= getIntent().getStringExtra("web_view_url");
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(mWebViewUrl);
setContentView(mWebview );
}
}
在清单中定义上述活动,如下所示:
<activity
android:name="<package-name>.AppWebViewActivity "
android:screenOrientation="portrait" >
</activity>
在这种情况下,您可以使用自定义ui—您必须用xml定义webview,并在webview活动中引用布局
编码快乐 您可以在应用程序中通过webview打开url步骤如下: 下面是webview的xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.whiskey.servicedog.DocumentPlay"
tools:showIn="@layout/activity_document_play">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true">
</WebView>
</RelativeLayout>
希望这对您有所帮助添加webview活动/片段,并在webview中显示网站。@Delta7您确定Facebook使用webview吗?不,他们制作了完整的appHello appersiano,此处未找到CustomTabsInt类。是的,当然可以,查看链接上的实施指南,你可以看到我正在寻找的gradle Dependency伟人。有没有办法给你100票。谢谢:)@appersiano是否可以向http://... url CustomTabsInt而不是https://..?Thanks 谢谢你的时间,但Webview不是我的解决方案。谢谢你的时间,但Webview不是我的解决方案。
Intent intent = new Intent(getBaseContext(), AppWebViewActivity .class);
intent.putExtra("web_view_url", "your-complete-url");
startActivity(intent)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.whiskey.servicedog.DocumentPlay"
tools:showIn="@layout/activity_document_play">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true">
</WebView>
</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_document_play);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(urlpath);
}