mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-25 08:38:30 -05:00
Explicitly persist and accept cookies. Resolves GH-36
This commit is contained in:
parent
3dc7e638ae
commit
a7ae9b586d
1 changed files with 18 additions and 0 deletions
|
@ -26,6 +26,7 @@ import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.webkit.ConsoleMessage;
|
import android.webkit.ConsoleMessage;
|
||||||
import android.webkit.CookieManager;
|
import android.webkit.CookieManager;
|
||||||
|
import android.webkit.CookieSyncManager;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
@ -261,6 +262,7 @@ public class ScratchJrActivity
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
_webView.onResume();
|
_webView.onResume();
|
||||||
|
CookieSyncManager.getInstance().startSync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
runJavaScript("if (typeof(ScratchJr) !== 'undefined') ScratchJr.onResume();");
|
runJavaScript("if (typeof(ScratchJr) !== 'undefined') ScratchJr.onResume();");
|
||||||
|
@ -274,6 +276,7 @@ public class ScratchJrActivity
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
_webView.onPause();
|
_webView.onPause();
|
||||||
|
CookieSyncManager.getInstance().stopSync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_databaseManager.close();
|
_databaseManager.close();
|
||||||
|
@ -367,6 +370,17 @@ public class ScratchJrActivity
|
||||||
// Uncomment to enable remote Chrome debugging on a physical Android device
|
// Uncomment to enable remote Chrome debugging on a physical Android device
|
||||||
//WebView.setWebContentsDebuggingEnabled(true);
|
//WebView.setWebContentsDebuggingEnabled(true);
|
||||||
|
|
||||||
|
// Enable cookie persistence
|
||||||
|
CookieManager.setAcceptFileSchemeCookies(true);
|
||||||
|
CookieManager cookieManager = CookieManager.getInstance();
|
||||||
|
cookieManager.setAcceptCookie(true);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
cookieManager.setAcceptThirdPartyCookies(_webView, true);
|
||||||
|
} else {
|
||||||
|
cookieManager.setAcceptCookie(true);
|
||||||
|
}
|
||||||
|
CookieSyncManager.createInstance(this);
|
||||||
|
|
||||||
/* Object exposed to the JavaScript that makes it easy to bridge JavaScript and Java */
|
/* Object exposed to the JavaScript that makes it easy to bridge JavaScript and Java */
|
||||||
JavaScriptDirectInterface javaScriptDirectInterface = new JavaScriptDirectInterface(this, (ScratchJrApplication) getApplication());
|
JavaScriptDirectInterface javaScriptDirectInterface = new JavaScriptDirectInterface(this, (ScratchJrApplication) getApplication());
|
||||||
_webView.addJavascriptInterface(javaScriptDirectInterface, "AndroidInterface");
|
_webView.addJavascriptInterface(javaScriptDirectInterface, "AndroidInterface");
|
||||||
|
@ -388,6 +402,10 @@ public class ScratchJrActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
|
// Sync cookies
|
||||||
|
CookieSyncManager.getInstance().sync();
|
||||||
|
|
||||||
|
// Track page load
|
||||||
String[] parts = url.split("/");
|
String[] parts = url.split("/");
|
||||||
_tracker.setScreenName(parts[parts.length - 1]);
|
_tracker.setScreenName(parts[parts.length - 1]);
|
||||||
_tracker.send(new HitBuilders.ScreenViewBuilder().build());
|
_tracker.send(new HitBuilders.ScreenViewBuilder().build());
|
||||||
|
|
Loading…
Reference in a new issue