public class MainActivity extends AppCompatActivity {
private WebView webView;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.loadUrl("file:///android_asset/index.html");
if(isNetworkConnected()){
}else{
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Closing Activity")
.setMessage("No Internet connection?")
.setPositiveButton("Exit", new DialogInterface.OnClickListener()
{
@Override public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
}
@Overridepublic void onBackPressed() {
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Closing Activity")
.setMessage("Are you sure you want to close this Application?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", null)
.show();
}
}
0 comments:
Post a Comment