Splash Screen.xml
Spalash screen.javapackage com.veer;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.Util.ApplicationUtil;
import java.util.Timer;
import java.util.TimerTask;
public class SplashActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Timer t = new Timer();
boolean checkConnection=new ApplicationUtil().checkConnection(this);
if (checkConnection) {
t.schedule(new splash(), 3000);
} else {
Toast.makeText(SplashActivity.this,
"connection not found...plz check connection", Toast.LENGTH_SHORT).show();
}
}
class splash extends TimerTask {
@Override public void run() {
Intent i = new Intent(SplashActivity.this,MainActivity.class);
finish();
startActivity(i);
}
}
}
Main Activity. xml
Maiin Activity.java
package com.veer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
static WebView webView;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyWebViewClient());
String url = "http://www.dharambirsingh_.com";
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
}
private class MyWebViewClient extends WebViewClient {
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override public void onBackPressed() {
if(webView.canGoBack())
webView.goBack();
else super.onBackPressed();
}
}
Util/ApplicationUtil.java
package com.veer.Util;
/** * Created by Aabit on 2016-09-05. */ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class ApplicationUtil {
ConnectivityManager connectivityManager;
NetworkInfo info;
public boolean checkConnection(Context context) {
boolean flag = false;
try {
connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
info = connectivityManager.getActiveNetworkInfo();
if (info.getType() == ConnectivityManager.TYPE_WIFI) {
System.out.println(info.getTypeName());
flag = true;
}
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
System.out.println(info.getTypeName());
flag = true;
}
} catch (Exception exception) {
System.out.println("Exception at network connection....." + exception);
}
return flag;
}
}
Androidmanifest.xml
Style.xml
No comments:
Post a Comment
Dharamart.blogspot.in