>. I& # 39, ve seen 대답 없는 낡은 데포스트프클리나 '' 이 함께 노력해야 할 수 있는 방법에 대해 >. 그러나 there& # 39 좋은 예로 '스테퍼리코네크션' 일은 아닙니다.
어느 시점에서 로그인하면 웹 응용 프로그램을 통해 실시간 페이지를 사용자에게 보여주고 싶다 '' 대신 '와' 스테퍼리코네크션 백그라운드에서 데이터를 다운로드하는 웹보기. 그러나 이전 같은 세션 I (i want to use 확립했습니다 준비되기까지 막기 위해 다시 로그인하십시오 필요가 없습니다.
How do I "에서 사용되는 '를' '쿠키' 복사합니다를 자바드네스쿠키만거 스테퍼리코네크션 안드로이d.웹킷.쿡리마나거 사용되는 '그래서 웹보기 공유할 수 있는' '세션?
제안하겠습니다 외곽진입 데이터베이스에구성원을 전혀 다른 문제다. 한 지점에서 다른 지점으로 (수동 sync), let& 복사하는 대신 쿠키 만들기, 쿠키 같은 # 39 의 스토리지 및 웹보기 스테퍼리코네크션 사용합니다.
이 완벽한 동기화를 위한 필요가 없습니다. 그 중 하나가 될 모든 쿠키 업데이트되도록 믿지아니하며 즉시 자동으로 반영되어, 다른.
이를 위해 직접 만들 수 있는 모든 # 39, WebViews& 자바드네스쿠키만거 구축 요청을 전달합니다. 웹킷 안드로이d.웹킷.쿨키메니지스터
구축상의:
import java.io.IOException;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class WebkitCookieManagerProxy extends CookieManager
{
private android.webkit.CookieManager webkitCookieManager;
public WebkitCookieManagerProxy()
{
this(null, null);
}
WebkitCookieManagerProxy(CookieStore store, CookiePolicy cookiePolicy)
{
super(null, cookiePolicy);
this.webkitCookieManager = android.webkit.CookieManager.getInstance();
}
@Override
public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException
{
// make sure our args are valid
if ((uri == null) || (responseHeaders == null)) return;
// save our url once
String url = uri.toString();
// go over the headers
for (String headerKey : responseHeaders.keySet())
{
// ignore headers which aren't cookie related
if ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
// process each of the headers
for (String headerValue : responseHeaders.get(headerKey))
{
this.webkitCookieManager.setCookie(url, headerValue);
}
}
}
@Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException
{
// make sure our args are valid
if ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null");
// save our url once
String url = uri.toString();
// prepare our response
Map<String, List<String>> res = new java.util.HashMap<String, List<String>>();
// get the cookie
String cookie = this.webkitCookieManager.getCookie(url);
// return it
if (cookie != null) res.put("Cookie", Arrays.asList(cookie));
return res;
}
@Override
public CookieStore getCookieStore()
{
// we don't want anyone to work with this cookie store directly
throw new UnsupportedOperationException();
}
}
마지막으로 이 에서 응용 프로그램 초기화하지 수행여 사용한다.
android.webkit.CookieSyncManager.createInstance(appContext);
// unrelated, just make sure cookies are generally allowed
android.webkit.CookieManager.getInstance().setAcceptCookie(true);
// magic starts here
WebkitCookieManagerProxy coreCookieManager = new WebkitCookieManagerProxy(null, java.net.CookiePolicy.ACCEPT_ALL);
java.net.CookieHandler.setDefault(coreCookieManager);
데포스트프클리나 ',' 에 비해 몇 가지 추가 단계를. 키 차이는 액세스하려면 스테퍼리코네크션 기존 에서 쿠키 '어떻게':
@Override
protected void onCreate(Bundle savedInstanceState) {
// Get cookie manager for WebView
// This must occur before setContentView() instantiates your WebView
android.webkit.CookieSyncManager webCookieSync =
CookieSyncManager.createInstance(this);
android.webkit.CookieManager webCookieManager =
CookieManager.getInstance();
webCookieManager.setAcceptCookie(true);
// Get cookie manager for HttpURLConnection
java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
CookieHandler.getDefault()).getCookieStore();
// Construct URI
java.net.URI baseUri = null;
try {
baseUri = new URI("http://www.example.com");
} catch (URISyntaxException e) {
// Handle invalid URI
...
}
// Copy cookies from HttpURLConnection to WebView
List<HttpCookie> cookies = rawCookieStore.get(baseUri);
String url = baseUri.toString();
for (HttpCookie cookie : cookies) {
String setCookie = new StringBuilder(cookie.toString())
.append("; domain=").append(cookie.getDomain())
.append("; path=").append(cookie.getPath())
.toString();
webCookieManager.setCookie(url, setCookie);
}
// Continue with onCreate
...
}
난 이미 같은 문제, 그리고 이건 내 해결책:
바로 다음에 로그인 (it& # 39 의 중요한 이유는, 아직 없는 쿠키 전에 # 39 don& 수도 있습니다) 를 사용하여 스테퍼리코네크션 게시물로의 (vora 제레스폰지코드), I do.
responseCode = connexion.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
final String COOKIES_HEADER = "Set-Cookie";
cookie = connexion.getHeaderField(COOKIES_HEADER);
...
}
(여기서 쿠키 는 공용 구체화하십시오 내 클래스)
또한 웹 페이지를 표시할 서버에서 웹보기 사용하여 웹보기 활동, where I, I do.
String url = "http://toto.com/titi.html"; // the url of the page you want to display
CookieSyncManager.createInstance(getActivity());
CookieSyncManager.getInstance().startSync();
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
cookieManager.setCookie(url, cookie);
CookieSyncManager.getInstance().sync();
난 이미 내 웹보기 그레이스티비티 사용할 수 있는 부분이 있다 () 를 컨텍스트로, 난 또 안드로이d.웹킷스 지정할 수 있었다. 그렇지 않으면 해결할 수 없는 (가져오기의 쿡리마나거 전에 java.net 대신 안드로이d.웹킷 쿠키 manager).
쿠키 () 는 위와 같은 문자열 (내 조각을 사용하여 해당 파일을 복구할 수 있었습니다.
cookie = getArguments().getString(COOKIE);
그리고 제, 제가 마리나스티비티 의해 보낸다.
Bundle arg = new Bundle();
arg.putString(Fragment_Cameras.COOKIE, cookie);
fragment.setArguments(arg);
내가 홉 (hop) 이 도움이 될 수 있습니다!