How to use cookies in Android Webview - android-webview

I am using a webview to render the contents of my Website.
I want to use Cookies in this webview to Auto Sign-In the users in that web site.
So, can anybody help how to use cookies in Android webview?

Enable your browser to accept cookies using CookieSyncManager. Everything else you wrote regarding cookies on your html side will work fine.
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
CookieManager.getInstance().setAcceptCookie(true);
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
setContentView(webview);
webview.loadUrl([MY URL]);

Related

I am using in app browser in ionic . Its opening the url on the mobile browser instead of app

I am using in app browser in ionic to implement my web in app.Its working fine but its opening the url on mobile browser instead of opening it on mobile app. I am using this in my .ts file
ngOnInit(){
this.iab.create('url','_self','location=no');
}
So adding _self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
So you need to have _blank instead.
Following should work as expected.
this.iab.create('url','_blank','location=no');
More info can be found here

How to detect url change through AngularJS in UIWebView

I am using UIWebView which load a url of website which using AngularJS. When its load an new url (AngularJS routing) its not detecting by UIWebView delegate . How can i detect if url change in browser.
Thanks
Get the current URL from window.location.href after the angular has been loaded, not from the UIWebView (webView.request?.url?.absoluteString).
webView.stringByEvaluatingJavaScript(from: "window.location.href")
Reason: It's mainly because the URL is internally managed by the Angular router.

Detect webview in Android with Javascript

There is an app on Google Play which is embedding my website in a webview. The app does nothing else, and includes a 3rd party monetization feature.
I want to detect when users are accessing my site via the app, so that I can show a message.
I haven't however been able to find a way to distinguish between the Android mobile browser and the app, as the user agents are the same.
Is there any known method to detect a webview?
Thanks.
Unfortunately, the answer is no, there isn't a way to distinguish between the Android mobile browser and another webview-based app.
Unless the app developer elects to modify the user agent, of course.
If you know the App ID of the app displaying your website through a webview, you can use PHP to detect if your site is being accessed through the app rather than a mobile browser by using the $_SERVER global array.
<?php
$app_id = "com.domain.appname";
$using_app = ( $_SERVER['HTTP_X_REQUESTED_WITH'] == $app_id ) ? TRUE: FALSE;
if ( $using_app ) {
echo "Using app message.";
}
?>
You can then use the $using_app variable to control content output and display a custom message.
This is all assuming of course you are server scripting your site via PHP.
You can also flag the app as copyright violator and ask Google to remove it from the market...

Phonegap - Open Links in Browser except embedded Videos

I'm Developing an App using Phonegap, target Devices are Android or iOS driven. My Problem is, that on the iPhone I can only set the "open all whitelist urls in webview" parameter to true or false. So that is the Problem:
Expected Result:
- All links (like www.google.com, www.stackoverflow.com) should open in the Browser
- An embedded iFrame with a Youtube Video should open in the Webview
Result with "OpenAllWhitelistUrlsInWebview" Set to true
- All links and iFrames will open in the Webview
Result with "OpenAllWhitelistUrlsInWebview" Set to false
- No links and iFrames will open in the Webview
How can i specify which links should open in the Browser and which shouldnt? When i remove an url from the whitelist the link won't open at all and also setting target="_blank" wont work properly. Trying it with window.open didn't work either.
Thank you very much for every idea.
Implemented this over the weekend, and it's working great:
http://www.rigelgroupllc.com/blog/2012/05/22/opening-links-in-phonegap-apps-in-mobile-safari/
This will allow you to set up your plist for the youtube video, while using the above method to open specified links in the external browser.
I'm not sure what/if you need to do anything in Android.

Is it possible to change iOS Safari settings programmatically

Is it possible to change Safari settings in a native app like following :
Accept Cookies : Never
Javascript: Off
Clear History, clear cookies and clear cache
Is the above possible and legal to do in a native app?
Nop. You can change the cookie settings for your app only.
I guess you are talking about a webview in your own application?
1) NO
You can delete them though: How to delete all cookies of UIWebView?
Also right after creation: Cookies in UIWebView
2) NO, its a system setting: UIWebView: Can You Disable Javascript?
3) There is no saved history in a webview. For cookies see 1),
for the Cache see: How to clear UIWebView cache?
Also interesting: UIWebView cache in iOS and Clearing UIWebview cache,