use of android.webkit.CookieManager in project GT by Tencent.
the class ShowhtmlActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gt_showhtml);
Intent intent = getIntent();
String action = intent.getStringExtra("uri");
String uri = Env.GT_HOMEPAGE;
if (action != null && !action.equals("")) {
uri = action;
}
String cookies = intent.getStringExtra("cookies");
webview = (WebView) findViewById(R.id.showhtml);
if (Build.VERSION.SDK_INT >= 11) {
// WebView安全性修改
try {
Method m = webview.getClass().getMethod("removeJavascriptInterface", String.class);
m.invoke(webview, "searchBoxJavaBridge_");
m.invoke(webview, "accessibility");
m.invoke(webview, "accessibilityTraversal");
} catch (NoSuchMethodException e) {
// 说明是Andorid2.3以下,do nothing
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webview.getSettings().setAppCacheEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setDatabaseEnabled(true);
if (cookies != null) {
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
// String oldCookie = cookieManager.getCookie(uri);
// ToastUtil.ShowLongToast(this, oldCookie);
cookieManager.setAcceptCookie(true);
// 移除
cookieManager.removeSessionCookie();
String[] cookieArray = cookies.split(";");
for (String cookie : cookieArray) {
if (!cookie.trim().isEmpty()) {
//cookies是在HttpClient中获得的cookie
cookieManager.setCookie(uri, cookie);
}
}
CookieSyncManager.getInstance().sync();
}
try {
webview.loadUrl(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.webkit.CookieManager in project SeriesGuide by UweTrottmann.
the class BaseOAuthActivity method activateWebView.
@SuppressLint("SetJavaScriptEnabled")
protected void activateWebView() {
buttonContainer.setVisibility(View.GONE);
webview.setVisibility(View.VISIBLE);
webview.setWebViewClient(webViewClient);
webview.getSettings().setJavaScriptEnabled(true);
// make sure we start fresh
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
webview.clearCache(true);
// load the authorization page
Timber.d("Initiating authorization request...");
String authUrl = getAuthorizationUrl();
if (authUrl != null) {
webview.loadUrl(authUrl);
}
}
use of android.webkit.CookieManager in project react-native-video by react-native-community.
the class ReactVideoView method setSrc.
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final int expansionMainVersion, final int expansionPatchVersion) {
mSrcUriString = uriString;
mSrcType = type;
mSrcIsNetwork = isNetwork;
mSrcIsAsset = isAsset;
mMainVer = expansionMainVersion;
mPatchVer = expansionPatchVersion;
mMediaPlayerValid = false;
mVideoDuration = 0;
mVideoBufferedDuration = 0;
initializeMediaPlayerIfNeeded();
mMediaPlayer.reset();
try {
if (isNetwork) {
// Use the shared CookieManager to access the cookies
// set by WebViews inside the same app
CookieManager cookieManager = CookieManager.getInstance();
Uri parsedUrl = Uri.parse(uriString);
Uri.Builder builtUrl = parsedUrl.buildUpon();
String cookie = cookieManager.getCookie(builtUrl.build().toString());
Map<String, String> headers = new HashMap<String, String>();
if (cookie != null) {
headers.put("Cookie", cookie);
}
setDataSource(mThemedReactContext, parsedUrl, headers);
} else if (isAsset) {
if (uriString.startsWith("content://")) {
Uri parsedUrl = Uri.parse(uriString);
setDataSource(mThemedReactContext, parsedUrl);
} else {
setDataSource(uriString);
}
} else {
ZipResourceFile expansionFile = null;
AssetFileDescriptor fd = null;
if (mMainVer > 0) {
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(mThemedReactContext, mMainVer, mPatchVer);
fd = expansionFile.getAssetFileDescriptor(uriString.replace(".mp4", "") + ".mp4");
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
if (fd == null) {
int identifier = mThemedReactContext.getResources().getIdentifier(uriString, "drawable", mThemedReactContext.getPackageName());
if (identifier == 0) {
identifier = mThemedReactContext.getResources().getIdentifier(uriString, "raw", mThemedReactContext.getPackageName());
}
setRawData(identifier);
} else {
setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
}
}
} catch (Exception e) {
e.printStackTrace();
return;
}
WritableMap src = Arguments.createMap();
src.putString(ReactVideoViewManager.PROP_SRC_URI, uriString);
src.putString(ReactVideoViewManager.PROP_SRC_TYPE, type);
src.putBoolean(ReactVideoViewManager.PROP_SRC_IS_NETWORK, isNetwork);
if (mMainVer > 0) {
src.putInt(ReactVideoViewManager.PROP_SRC_MAINVER, mMainVer);
if (mPatchVer > 0) {
src.putInt(ReactVideoViewManager.PROP_SRC_PATCHVER, mPatchVer);
}
}
WritableMap event = Arguments.createMap();
event.putMap(ReactVideoViewManager.PROP_SRC, src);
mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD_START.toString(), event);
// not async to prevent random crashes on Android playback from local resource due to race conditions
try {
prepare(this);
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.webkit.CookieManager in project robolectric by robolectric.
the class ShadowCookieManagerTest method shouldGetCookieForUrl.
@Test
public void shouldGetCookieForUrl() {
CookieManager cookieManager = CookieManager.getInstance();
String url1 = "http://www.google.com";
String value1 = "my cookie";
cookieManager.setCookie(url1, value1);
String url2 = "http://www.hotbot.com";
String value2 = "some special value: thing";
cookieManager.setCookie(url2, value2);
assertThat(cookieManager.getCookie("http://www.google.com")).isEqualTo(value1);
assertThat(cookieManager.getCookie(url2)).isEqualTo(value2);
}
use of android.webkit.CookieManager in project robolectric by robolectric.
the class ShadowCookieManagerTest method shouldGetCookieForHostInDomain.
@Test
public void shouldGetCookieForHostInDomain() {
CookieManager cookieManager = CookieManager.getInstance();
String value1 = "my cookie";
cookieManager.setCookie("foo.com/this%20is%20a%20test", value1);
assertThat(cookieManager.getCookie(".foo.com")).isEqualTo(value1);
}
Aggregations