Adding Cookie Support for Android Devices

This commit is contained in:
Stephen Mudra 2016-05-11 15:55:09 +08:00
parent 7db95e2c7f
commit f617f445a6

View File

@ -3,6 +3,10 @@ package com.brentvatne.react;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.net.Uri;
import android.webkit.CookieManager;
import java.util.Map;
import java.util.HashMap;
import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ThemedReactContext;
@ -122,7 +126,24 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
mMediaPlayer.reset(); mMediaPlayer.reset();
try { try {
if (isNetwork || isAsset) { 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) {
setDataSource(uriString); setDataSource(uriString);
} else { } else {
setRawData(mThemedReactContext.getResources().getIdentifier( setRawData(mThemedReactContext.getResources().getIdentifier(