gpt4 book ai didi

java - 在单独的 WebView 上进行多次登录? (安卓)

转载 作者:太空狗 更新时间:2023-10-29 15:11:07 25 4
gpt4 key购买 nike

我是 Android 开发的新手,我对 WebView 如何处理数据(在 Java 中)有疑问。

我假设这属于“cookie”类别。但是我在我的应用程序的不同选项卡上有两个不同的 webView。我希望将一个 webView(称为 webView1)登录到网站的一个帐户,而另一个(webView2)登录到同一网站的另一个帐户网站。例如,我想在两个 webView 中同时登录两个单独的 Gmail 帐户。

我遇到的问题是,一旦我登录到 webView1 上的帐户,webView2 就会效仿并将我登录到该帐户。当我登录 webView2 时,也会出现同样的问题,因为 webView1 也会自然地登录该帐户。

有什么办法可以解决这个问题吗?归根结底,我希望我的两个 webView 彼此完全独立地运行。

谢谢!

最佳答案

我可以肯定地回答你的问题。我主要是一名 iOS 开发人员,我正在创建一个 Android 应用程序,其效果与 webView cookies 不共享完全相反。我在选项卡中创建了我的 webviews 来模拟我在 iOS 中使用的行为,但我的 webviews 完全独立于彼此。我希望他们共享相同的登录信息,但就目前而言,我必须单独登录每个选项卡,因为他们玩得不好。

无论如何,我的问题绝对可以帮助您,我希望您与我分享您的信息以创建我正在寻找的 cookie 共享效果...

这是我的 main.xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<WebView
android:id="@+id/web_engine"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="-45dp" />
<WebView
android:id="@+id/messages"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="-45dp" />
<WebView
android:id="@+id/myprofile"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="-45dp" />
<WebView
android:id="@+id/rncorner"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="-45dp" />
</FrameLayout>
</LinearLayout>
</TabHost>

这是我的 Activity :

package com.example.tabs;


import android.app.TabActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;

public class TabsActivity extends TabActivity {
WebView webView;

final String DEFAULT_URL = "http://example.com";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TabHost mTabHost = getTabHost();

mTabHost.addTab(mTabHost.newTabSpec("Home").setIndicator("Home",getResources().getDrawable(R.drawable.home)).setContent(R.id.web_engine));
mTabHost.addTab(mTabHost.newTabSpec("Messages").setIndicator("Messages",getResources().getDrawable(R.drawable.messages)).setContent(R.id.messages));
mTabHost.addTab(mTabHost.newTabSpec("My Profile").setIndicator("My Profile", getResources().getDrawable(R.drawable.myprofile)).setContent(R.id.myprofile));
mTabHost.addTab(mTabHost.newTabSpec("Map").setIndicator("Map", getResources().getDrawable(R.drawable.rncorner)).setContent(R.id.rncorner));

mTabHost.setCurrentTab(0);

//home
webView = (WebView)findViewById(R.id.web_engine);

webView.setWebViewClient(new MyWebViewClient());

webView.loadUrl(DEFAULT_URL);

//messages
webView = (WebView)findViewById(R.id.messages);

webView.setWebViewClient(new MyWebViewClient());

webView.loadUrl("http://example.com/index.php2");

//my profile
webView = (WebView)findViewById(R.id.myprofile);

webView.setWebViewClient(new MyWebViewClient());

webView.loadUrl("http://example.com/index.php3");


//rncorner
webView = (WebView)findViewById(R.id.rncorner);

webView.setWebViewClient(new MyWebViewClient());

webView.loadUrl("http://example.com/index.php4");

}



public class MyWebViewClient extends WebViewClient {



@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

// TODO Auto-generated method stub

view.loadUrl(url);

return true;

}


}
}

关于java - 在单独的 WebView 上进行多次登录? (安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16259313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com