多用户登录功能的独立网页视图? (Android版) [英] Multiple Log-Ins on Separate WebViews? (Android)

查看:208
本文介绍了多用户登录功能的独立网页视图? (Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的Andr​​oid的发展,我有一个关于网页视图如何处理数据(在Java中)的问题。

I'm fairly new to Android development, and I have a question about how WebViews handle data (in Java).

我假定这将归入'饼干'类别。但是,我有什么是我的应用程序的不同选项卡两种不同的网页视图。我想对于一个web视图(称之为 webView1 )将被记录到一个帐户的网站,而其他( webView2 )将登录到同一网站的另一个帐户。例如,我想登录到这两个网页视图中的两个独立的Gmail账户在同一时间。

I'm assuming this would fall under the 'cookie' category. But what I have is two different webViews on different tabs of my application. I would like for one webView (call it webView1) to be logged into one account of a website, while the other (webView2) to be logged into another account of the same website. For example, I would want to log into two separate Gmail accounts within the two webViews at the same time.

我遇到的问题是,一旦我登录上 webView1 webView2 账户跟风和日志我该帐户。当我登录到 webView2 同样的问题发生,如 webView1 登录到该帐户也自然。

The problem I am having is that once I log into an account on webView1, webView2 follows suit and logs me into that account. The same problem happens when I log into webView2, as webView1 logs into that account also naturally.

有没有什么办法来解决这个问题?我想我的两个网页视图完全独立行事彼此是它归结为。

Is there any way to get around this? I want my two webViews to act completely independently from one another is what it comes down to.

谢谢!

推荐答案

我可以肯定地回答你的问题。我主要是iOS开发人员,我创建具有web视图饼干不共享的完全相反效果的Andr​​oid应用程序。我创建了网页视图中的标签来模拟我的iOS使用的行为,但我的网页视图的行为是完全独立的彼此。我希望他们能够共享相同的登录信息,但因为它的立场,我必须,因为他们没有打漂亮单独登录到每个选项卡。

I can definitely answer your question. I am mainly an iOS developer and I am creating an Android app with the exact opposite effect of webView cookies not sharing. I created my webviews in tabs to simulate the behavior I use in iOS, but my webViews are acting completely independant of one another. I want them to share the same login info, but as it stands I must login to each tab individually because they aren't playing nice.

无论哪种方式,我的问题绝对可以帮助你,我希望你与我分享你的信息,以创建cookie的共享效果我正在寻找...

Either way, my problem can definitely help you and I would hope that you share your info with me to create the cookie sharing effect I am searching for...

下面是我的main.xml中的布局:

Here is my main.xml layout:

<?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>

下面是我的活动:

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;

    } 


}
}

这篇关于多用户登录功能的独立网页视图? (Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆