Android authentication via webview - android

I'm sorry for this as I am very Green at this Android Development, and I maybe beating a dead horse here-
A software tjat we use has a mobile version, but it's a mobile website, I am trying to build this into a standalone web-app using webview.
The app will get me to the login screen, but when I attempt to login the the pop-up showing its logging in, and in my webview, it is sticking there. It doesn't move past this point.
In the default browser it works fine.
Can you please assist me in what I need to do to get pass this in the most simple terms? ;-) Thank you!
package com.giantflyingsaucer;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebPageLoader extends Activity
{
final Activity activity = this;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("http://URL.USED.FOR/WEBAPP");
}
}

This was resolved by using
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

perhaps your login is trying to make use of some web plugin. Try adding one or both of these:
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.getSettings().setPluginsEnabled(true);

Related

My application keeps on crashing using Webview?

I'm just testing my application at the moment. However, it keeps on crashing on the loading screen. Once it loads it redirects to the login or users account if they have already logged in.
However, I keep getting these error messages in android studios console log when built the application.
W/cr_CrashFileManager: /data/user/0/chrisbeckett.********/cache/WebView/Crash Reports does not exist or is not a directory
// I've put the stars as I can't show the name of the application yet.
W/cr_AwContentsClient: Denied starting an intent without a user gesture, URI http://********.********.com/login
My current code:
package chrisbeckett.**********;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
private WebView mWebView;// Instance of WebChromeClient for handling all chrome functions.
private volatile WebChromeClient mWebChromeClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setAppCacheEnabled(true);
webSettings.setAppCacheMaxSize(100 * 1000 * 1000);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.loadUrl("http://********.*********.com/loading");
}
/**
* Set the WebChromeClient.
* #param client An implementation of WebChromeClient.
*/
public void setWebChromeClient(WebChromeClient client) {
mWebChromeClient = client;
}
}
Further information:
My code works on all web browsers on a desktop when viewing it in a mobile mode in the inspector when testing before putting it in App format.
If you require any more information please let me know.
try below code this may work
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
You can use it for Android N
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#SuppressWarnings("deprecation")
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
#TargetApi(Build.VERSION_CODES.N)
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
});
android:usesCleartextTraffic="true" in application tag
add above line in your manifest.xml file.

WebView Taking Long time to load

I am integrating Skrill payment gateway with my android app.As there is no available sdk so I have to redirect my app to skrill homepage.I am using a webview.But the problem is the webview is not showing the webpage and it shows blank screen.I cant figure out the problem.Any help will be appreciated.
Here is my code:
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
WebView wbskrill;
String url;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wbskrill=(WebView)findViewById(R.id.wbv);
url="https://www.skrill.com/en/";
wbskrill.setWebViewClient(new MyBrowser());
}
//wbskrill.setWebViewClient(new WebViewClient());
public void open(View view){
wbskrill.getSettings().setLoadsImagesAutomatically(true);
wbskrill.getSettings().setJavaScriptEnabled(true);
wbskrill.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wbskrill.loadUrl(url);
}
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
In this case overide methods of webview use to handle SSL certificate and accept ssl certificate it will run successfully.
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed() ;
}
In your case
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed() ;
}
}
For more info see this link Android WebView with https loadUrl shows blank/empty page

Playing video in webview

I would like to build an app that accesses youtube.com/tv in a webview for android set top boxes. I can get it to work by loading with html5webview but it takes for ever. I have noticed that this is the way the android browser does it. I have been using opera mobile lately and have noticed that it runs flawlessly, it also states in opera that my pugins are not enabled.
Question 1: How is opera Mobile rendering video on youtube.com/tv, does it ship with its own flash?
Question 2 What is the best way to implement this? I have reverted my code to basic webView for fresh start.
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class TvbrowserActivity extends Activity
{
final Activity activity = this;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
String ua = " Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19";
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setUserAgentString(ua);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("http://youtube.com/tv");
}
}
I also have hardware accelerated set in activity in android manifest
Check if the code is helpful or not
myWebView = (WebView) findViewById( R.id.webView );
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
myWebView.loadUrl("http://www.youtube.com/v/nVLcujAj67g?version=3");

Why is my WebView's WebViewClient not being called?

I have a WebView, and after setting up a custom WebViewClient with WebView.setWebViewClient, the WebViewClient methods do not seem to be called. In particular I'm overriding onLoadResource and onReceivedError. However, neither of these are called after calling WebView.loadUrl();
Here's the code in question: https://gist.github.com/9673b619e019038848a0
What am I missing?
Are you sure you are looking for the correct log message and that your device is outputting logging properly? I essentially copied your code into a clean project and it appears to work perfectly. Glancing at the documentation it looks like you are following everything properly.
I am using the webview as the content view, that is the only significant difference I see.
For reference here is my test activity:
package com.testing.androidtest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
private static final String APP_TAG = "MYAPP";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final WebView webView = new WebView(getApplicationContext());
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Log.d(APP_TAG, consoleMessage.message());
return true;
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e(APP_TAG, "Error in WebView: " + failingUrl + "; " + description);
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
Log.d(APP_TAG, "loading resource: " + url);
}
});
webView.loadUrl("http://google.com/");
setContentView(webView);
}
}

Need assistance using phones back button to go back in Webview

This is my code:
package com.testappmobile;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class testappmobileActivity extends Activity
{
final Activity activity = this;
private WebView webview;
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the BACK key and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
// If it wasn't the BACK key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("http://developer.android.com/index.html");
}
}
Now im having trouble getting the hardware back button to work. The app loads fine as does page and everything else but as soon as i hit the phones back button it crashes then forces close.
I've searched google for the last 3 hours and have only found vague answers with very little info or broken links. Google's instructions sucked also as i am a beginner and they presume you know a certain amount.
Where should I place the code if it is in the wrong place?
Are there errors?
Cheers!
You have created a webView reference at class level but never initialized it thats why NullPointerException. I've made a small change in the onCreate method in your code, analyze it and make the necessary change(s);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
// Don't create another webview reference here,
// just use the one you declared at class level.
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
// rest of code same
// ...
// ...
// ...
}
Hope you got it. :)
You have two different references to WebView. First local in onCreate, that is lost. Second webview member that you use in onKeyDown, but that is null all the time.

Categories

Resources