用APP的webView登录,然后退出应用,用UC之类的webview浏览器内核再去那个网页能免登录,请教下应该怎么实现,求思路

在android的app中用WebView实现浏览网页功能 - 简书
在android的app中用WebView实现浏览网页功能
java代码:
//设置支持js脚本
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setDomStorageEnabled(true);
//设置进度条
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100 && !CoveritLIveActivity.this.isFinishing()) {
progressBar.setVisibility(View.INVISIBLE);
if (View.INVISIBLE == progressBar.getVisibility() && !CoveritLIveActivity.this.isFinishing()) {
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(newProgress);
super.onProgressChanged(view, newProgress);
// 覆盖webView默认通过系统或者第三方浏览器打开网页的行为
// 如果为false调用系统或者第三方浏览器打开网页的行为
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// webView加载web资源
view.loadUrl(url);
webView.loadUrl(Url);
&?xml version="1.0" encoding="utf-8"?&
&RelativeLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:app="/apk/res-auto"
&com.easemob.easeui.widget.EaseTitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
app:titleBarLeftImage="@drawable/back"
app:titleBarTitle="" /&
&ProgressBar
android:id="@+id/myProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@id/title_bar" /&
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/myProgressBar" /&
&/RelativeLayout&问下大家,android 调用webview 进行展示的时候,可以指定第三方浏览器吗?比如uc浏览器_问答_ThinkSAAS
问下大家,android 调用webview 进行展示的时候,可以指定第三方浏览器吗?比如uc浏览器
问下大家,android 调用webview 进行展示的时候,可以指定第三方浏览器吗?比如uc浏览器
如题,请教下大家,android 调用webview 进行展示的时候,可以指定第三方浏览器吗?比如我的webveiw 想在应用中调用uc浏览器进行界面展现,需要怎么设置呢?因为4.4.2 的android webview 不支持flash了,但uc浏览器可以,所以现在想在app里的webview 指定使用uc。
这是不可能的,因为UC浏览器是独立的应用,有自己的activity,你没办法把它的view变成自己应用的view。
UC浏览器应该通过native来支持flash文件的,就是源码里有不少.so文件,如果你没有能力写出来,那我建议趁早放弃flash支持吧,youtube现在PC浏览器端都已经放弃flash了。
实在想用UC的flash的话,只能打开一个intent了。
javaprivate void openUrl(String url){
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse(url));
intent.setClassName("com.uc.browser","com.uc.browser.ActivityUpdate");
startActivity(intent);
添加你想要问的问题
PHP开发框架
开发工具/编程工具
服务器环境使用WebView实现新浪微博OAuth登录 - 程序人生 - ITeye技术网站
博客分类:
#新浪官方下载SDK(weibo4android)
/wiki/index.php/SDK
#申请应用KEY
登录新浪微博,进入/申请应用,获取KEY和SECRET。
在项目中导入commons-httpclient-3.x.jar并加入weibo4android、weibo4android.http、weibo4android.org.json、weibo4android.util包文件(这些都是官方下载的SDK提供的文件)
在跳转到新浪微博授权页面时会使用默认浏览器,这个不太好看,也有些用户手机用其他如UC等浏览器。因此,我决定用WebView代换默认浏览器。
默认浏览器
WebView代换
在我的项目中,有多个应用项目需要OAuth登录,因此需要做成共通,也考虑到应用今后可能会支持如腾讯微博、人人网、支付宝等多种方式登录,所以我的代码考虑了“开-闭原则”。
package com.
import android.app.A
import android.os.B
import android.view.V
import android.view.View.OnClickL
public class ShareWithOAuthActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.share_button).setOnClickListener(new OnClickListener() {
public void onClick(View button) {
OAuth.share(ShareWithOAuthActivity.this);
package com.
import com.db.DbH
import android.app.AlertD
import android.content.C
import android.content.DialogI
import android.content.I
import android.database.C
import android.widget.T
public class Share {
public static final String SINA = "sina";
public static final String TENCENT = "tencent";
private static AlertDialog alertDialog =
private static String[] shareList =
private static String[] fullShareList =
public static void share(final Context context, final String content) {
if (shareList == null) {
shareList = context.getResources().getStringArray(R.array.share_list);
fullShareList = new String[shareList.length];
for (int i=0; i&shareList. i++) {
fullShareList[i] = "分享到" + shareList[i];
if (alertDialog == null) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setTitle("分享");
dialogBuilder.setItems(fullShareList, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int position) {
String flag = text2Flag(context, shareList[position]);
if (flag != null) {
oauthLogin(context, flag, content);
alertDialog = dialogBuilder.create();
alertDialog.show();
public static String text2Flag(Context context, String text) {
String result =
if ("新浪微博".equals(text)) {
result = SINA;
} else if ("腾讯微博".equals(text)) {
result = TENCENT;
Toast.makeText(context, "没有匹配的类型", Toast.LENGTH_SHORT).show();
public static void oauthLogin(Context context, String flag, String content) {
Intent intent = new Intent();
intent.putExtra("oauth_type", flag);
intent.putExtra("share_content", content);
Cursor cursor = DbHelper.getUserByFlag(flag);
if (cursor != null && cursor.moveToFirst()) {
intent.putExtra("token", cursor.getString(cursor.getColumnIndex("token")));
intent.putExtra("secret", cursor.getString(cursor.getColumnIndex("secret")));
intent.setClass(context, ShareActivity.class);
if (SINA.equals(flag)) {
intent.setClass(context, SinaOAuth.class);
} else if (TENCENT.equals(flag)) {
intent.setClass(context, TencentOAuth.class);
if(cursor != null) cursor.close();
context.startActivity(intent);
res/layout/oauth_webview_layout.xml
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"&
&TextView android:id="@+id/oauth_webview_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#996633"
android:textColor="#000"
android:textSize="18dp" /&
&WebView android:id="@+id/oauth_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /&
&/LinearLayout&
package com.
import android.app.A
import android.content.I
import android.net.U
import android.os.B
import android.webkit.WebV
import android.widget.TextV
import android.webkit.WebViewC
public abstract class OAuthActivity extends Activity {
protected static OAuthActivity oauthA
protected TextView titleV
protected WebView oauthWebV
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.oauth_webview_layout);
initViews();
oauthLogin();
private void initViews() {
titleView = (TextView)findViewById(R.id.oauth_webview_title);
oauthWebView = (WebView)findViewById(R.id.oauth_webview);
oauthWebView.getSettings().setJavaScriptEnabled(true);
oauthWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url == null)
if (url.startsWith("weibo4android")) {
Intent intent = new Intent(OAuthActivity.this, CallbackActivity.class);
intent.setData(Uri.parse(url));
OAuthActivity.this.startActivity(intent);
view.loadUrl(url);//腾讯微博在载入授权页面时会跳转,这里不写会用默认浏览器加载页面
protected abstract void oauthLogin();
protected abstract void callback(Intent callbackIntent);
public static void postLogin(Intent callbackIntent) {
if (oauthActivity != null) {
oauthActivity.callback(callbackIntent);
oauthActivity =
package com.
import com.db.DbH
import weibo4android.W
import weibo4android.WeiboE
import weibo4android.http.AccessT
import weibo4android.http.RequestT
import android.content.I
import android.net.U
import android.os.B
public class SinaOAuth extends OAuthActivity {
private RequestToken requestT
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
titleView.setText("新浪微博登录");
protected void oauthLogin() {
System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
Weibo weibo = new Weibo();
requestToken = weibo.getOAuthRequestToken("weibo4android://CallbackActivity");
Uri uri = Uri.parse(requestToken.getAuthenticationURL()+ "&display=mobile");
oauthWebView.loadUrl(uri.toString());//自定义WebView
} catch (WeiboException e) {
e.printStackTrace();
oauthActivity =//此处很关键
public void callback(Intent callbackIntent) {
Uri uri = callbackIntent.getData();
AccessToken accessToken =
accessToken = requestToken.getAccessToken(uri.getQueryParameter("oauth_verifier"));
} catch (WeiboException e) {
e.printStackTrace();
DbHelper.persistUser(Share.SINA, accessToken.getUserId(), accessToken.getToken(), accessToken.getTokenSecret());
Intent intent = this.getIntent();
intent.putExtra("oauth_type", Share.SINA);
intent.putExtra("token", accessToken.getToken());
intent.putExtra("secret", accessToken.getTokenSecret());
intent.setClass(this, ShareActivity.class);
this.startActivity(intent);
this.finish();
package com.
import android.app.A
import android.os.B
public class CallbackActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OAuthActivity.postLogin(this.getIntent());
&?xml version="1.0" encoding="utf-8"?&
&manifest xmlns:android="/apk/res/android"
package="com.oauth"
android:versionCode="1"
android:versionName="1.0"&
&uses-sdk android:minSdkVersion="7" /&
&uses-permission android:name="android.permission.INTERNET" /&
&application android:name="monApplication"
android:icon="@drawable/icon"
android:theme="@style/theme"
android:label="@string/app_name"&
&activity android:name=".ShareWithOAuthActivity"
android:label="@string/app_name"&
&intent-filter&
&action android:name="android.intent.action.MAIN" /&
&category android:name="android.intent.category.LAUNCHER" /&
&/intent-filter&
&/activity&
&activity android:name=".CallbackActivity"&
&intent-filter&
&action android:name="android.intent.action.VIEW" /&
&category android:name="android.intent.category.DEFAULT" /&
&category android:name="android.intent.category.BROWSABLE" /&
&data android:scheme="weibo4android" android:host="CallbackActivity" /&
&/intent-filter&
&/activity&
&activity android:name=".SinaOAuth" android:theme="@android:style/Theme.NoTitleBar" /&
&activity android:name=".TencentOAuth" android:theme="@android:style/Theme.NoTitleBar" /&
&activity android:name=".ShareActivity" android:launchMode="singleTask"/&
&activity android:name=".ChangeAccountActivity" /&
&/application&
&/manifest&
这种做法,网速稍微慢一点,应该很容易出anr的情况url请求可以在异步线程中执行
chenfeng0104
浏览: 401440 次
来自: 上海
误人子弟的文章。已经看到N个人转了这个帖子,这要贻害多少新人啊 ...
特意登录上来,感谢下!
总结的好,有效。
实测通过ApplicationContext ac = new ...

我要回帖

更多关于 webview不跳转浏览器 的文章

 

随机推荐