Android app that connects to IIS website using windows authentication - android

I have started playing with developing apps for the android. I have a site hosted on an IIS server that uses Windows authentication. I want to connect to it through my app. When I access the site from a computer or phone it prompts for the username and password. However, I cannot get the webview to pop up the credentials prompt, nor have I been able to pass the username and password to the site in my Main_Activity when using the emulator (target 4.4 API 19).
I have been working on this for a while looking a tons of examples. It's difficult to relate the code I have seen to my specific situation, I have copied and pasted number examples. I keep getting 401 unauthorized when the page comes up.
I am trying to stick with the android app thing this time, so any help would be greatly greatly appreciated. Below is my last attempt:
Here are 2 methods I have created or modified. There are seperate from one another.
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("URL:8080/");
}
"More code.."
public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm){
String[] up = view.getHttpAuthUsernamePassword("username", "password");
if( up != null && up.length == 2 ) {
handler.proceed(up[0], up[1]);
}
}
}

Related

cordova webview is not saving passwords on form submit

I have an android app with CordovaActivity which loads a login page for wordpress website using loadUrl("loginurl"), when the user enters his credentials for the first time a prompt asks for password remembering, however when the user closes the app and reopen it the password field is cleared and just got the username remembered.
when using the native android webview for the same site the password is saved correctly but I need to use cordova in my app, any idea how to make CordovaWebview remember wordpress login password?
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
LOGIN_URL = getString(R.string.site_url) + "/wp-login.php";
// Set by <content src="index.html" /> in config.xml
loadUrl(LOGIN_URL);
}
After 3 months I found a solution, for some reason when you use webview and load the WP login page, wordpress clears the password filed if you are already logged in instead of redirecting you to the home page, the solution was to not load the login page on application start up and just load the home page and put a login widget.

Robotium Test to Extract Cookies from WebView

My Sign Up Process produces cookies in a WebView, not in native code. All my tests depend on the cookies retrieved from the Webview so I need a way to extract data from a webview inside a Robotium test. How can this be done? Here is my WebView fragment:
public class MyWebViewFragment extends Fragment {
private CookieManager cookieManager;
#ViewById
WebView myWebView;
#AfterViews
void theAfterViews() {
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setDomStorageEnabled(true);
CookieSyncManager.createInstance(getActivity());
cookieManager = CookieManager.getInstance();
myWebView.loadUrl(theURL);
myWebView.setWebViewClient(new WebViewClient()
{
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if ((url != null) && (url.equals(theURL)))
{
String theCookies = cookieManager.getCookie(url);
// ######## I need to pull these Cookies out here in the Robotium test. How do I use Solo etc to do this?
}
}
}
}
I need to know how to write a Robotium test that will at the right point pull out the values of the Cookies and save it for the rest of the tests to use. I need to get thiw working or none of my other tests will run. Thanks
The simple answer as i think you may know having seen your other questions is to get hold of the fragment and then ask the fragment for the value. Potentially you might consider mocking this functionality out for your tests or allow your tests a method to be able to set the cookies for itself etc (not sure if this is feasible for your case or not.)

Android webview app and Google Analytics

I have a simple native Android app that is a webview of a website, effectively to make the mobile-ready site native-like if you will. The website already has Google Analytics installed.
What might be a good way to track which visitors are using the app?
I could adding Android Native App Tracking, but I presume that would
double track the users. Unless it's smart enough to connect the visits?
I could pass custom get variable to the site that maybe adds a custom
attribute to the tracking for native app users. But that doesn't
sound very clean.
What might be best for tracking? I feel there's got to be an obvious answer I'm missing.
that should help you:
Now getting back to the Analytics tracking of this web app, I used the code provided by Google here.
So the code becomes somewhat like this.
public class myWebApp extends Activity{
Webview mWebview;
GoogleAnalyticsTracker tracker;
protected void onCreate(Bundle savedInstanceState) {
tracker = GoogleAnalyticsTracker.getInstance();
// Start the tracker in manual dispatch mode. The following UA-xxxxxxx-x code must be replaced by //your web property ID.
tracker.startNewSession("UA-xxxxxxx-x", this);
mWebview = new WebView(this);
mWebview .setWebViewClient(new myWebViewClient());
mWebview .loadUrl("file:///android_asset/www/index.html");
private class myWebViewClient extends WebViewClient
{
//After the user visits a particular page, send the tracking notification to GoogleAnalytics.
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
tracker.trackPageView( mWebview.getUrl());
tracker.dispatch();
}
}
}
http://www.the4thdimension.net/2011/11/using-google-analytics-with-html5-or.html
And in stats of google analytics you should get some info at least about operating system android.

How to handle a binary data response in WebView

My activity has an intent filter to pick up a specific url and open it in a WebView control, which brings user to an auth page (user name/password). After authentication is done user will get a binary stream response (file). Is there a way to handle that response and read data from the stream?
I tried to setup a custom WebViewClient with the overridden shouldOverrideUrlLoading method, but app doesn't get there.
#Override
mMyWebView.setWebViewClient(new CustomWebClient());
mMyWebView.loadUrl("http://xxx.xx.x.xx:xxxx/getCert");
...
private class CustomWebClient extends WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading (WebView view, String urlConection)
{
// break point here doesn't stop debugger
return true;
}
}
neither works
mMyWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading (WebView view, String urlConection)
....
});
Server reacts on requests in the same way from both My app and build-in browser. Build-in browser starts to download file received in response, but my app doesn't do anything and doesn't hit breakpoint inside CustomWebClient.
This is a separate app just to test this piece nothing else interferes with it. INTERNET & WRITE_EXTERNAL_STORAGE permissions added.
EDIT: Mar 8
Gave up. Will go with httpClient.
Did you implement this method of WebView?
void setDownloadListener(DownloadListener listener)
Register the interface to be used when content can not be handled by the rendering engine, and should be downloaded instead.

Loading a Maps API site in a Native Android Application

I'm trying to follow the example from google:
http://code.google.com/apis/maps/articles/android_v3.html
Using the example files from their SVN repo:
(http)gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/
But although it seems to compile and export it fails; can someone sanity check that its not just me this fails for and any hints as to if its a quick thing to fix, I've been prodding it with try/catch for the last 2 hours to no avail.
Thanks :o)
Forgot to add
It Compiles and Uploads to the emulator (and to my phone) but running it just results in
The Application WebMapActivity (process com.google.android.examples.webmap)
has stopped unexpectedly. Please try again. [Force Close]
Filtered it down to
private void setupWebView() {
/*
final String centerURL = "javascript:centerAt("
+ mostRecentLocation.getLatitude() + ","
+ mostRecentLocation.getLongitude() + ")";
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
// Wait for the page to load then send the location information
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl(centerURL);
}
});*/
webView = (WebView) findViewById(R.id.webview);
webView.loadUrl(MAP_URL);
}
Bit easier to filter out the actual issue when you know which bit doesnt work thanks to CommonsWare for the great book, poking through that and test-code that ACTUALLY WORKS made it a bit easier to work out what was going on. And thanks for the debug info :o)

Categories

Resources