Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Facing java.lang.SecurityException just checking internet is present or not
    primarykey
    data
    text
    <p>I have no idea why this exception is coming, I'm just checking whether internet is present or not. And if internet is present im opening a link thats it.</p> <p>The strange thing is that i used the same code in other project and it worked without any problem.</p> <p><strong>Also, *<em>I have already given internet permission</em>*</strong></p> <p>Here is my code</p> <pre><code>package com.siddharth.empyrealrealty; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.graphics.Bitmap; import android.media.MediaPlayer; import android.os.AsyncTask; import android.os.Bundle; import android.view.Menu; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class Main extends Activity { WebView wv; ProgressDialog pg; Background bg; boolean isInternetPresent = false; AlertDialog.Builder alert; MediaPlayer exceptionNotifier; ConnectionDetector cd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // overridePendingTransition(R.anim.fadein, R.anim.fadeout); setContentView(R.layout.activity_main); alert = new AlertDialog.Builder(this); cd = new ConnectionDetector(this); try { isInternetPresent = cd.isConnectingToInternet(); } catch (Exception e) { Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show(); } if(isInternetPresent){ Toast.makeText(getApplicationContext(), "Loading... Please Wait..", Toast.LENGTH_LONG).show(); wv=(WebView)findViewById(R.id.webView1); bg = new Background(); bg.execute(); }else{ exceptionNotifier = MediaPlayer.create(getApplicationContext(), R.raw.notify); exceptionNotifier.start(); alert.setTitle("Alert!"); alert.setMessage("Internet Not Present..! "); alert.setCancelable(true); alert.setPositiveButton("Ok!", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub exceptionNotifier.release(); } }).show(); } } public void progress(){ pg = new ProgressDialog(this); pg.setTitle(""); pg.setMessage("Please Wait........."); pg.setCancelable(false); pg.setIndeterminate(true); pg.show(); } class Background extends AsyncTask&lt;Void, Void, Void&gt; { @SuppressLint("SetJavaScriptEnabled") @Override protected Void doInBackground(Void... arg0) { // TODO Auto-generated method stub try{ wv.loadUrl("http://www.siddharth.uphero.com"); }catch(Exception e){ e.printStackTrace(); } wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setLoadWithOverviewMode(true); wv.getSettings().setUseWideViewPort(true); wv.getSettings().setBuiltInZoomControls(true); wv.setWebViewClient(new MyWebClient()); return null; } @Override protected void onPostExecute(Void result) { } @Override protected void onPreExecute() { progress(); } } public class MyWebClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStarted(view, url, favicon); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { // TODO Auto-generated method stub super.onPageFinished(view, url); pg.dismiss(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>Heres the code for ConnectionDetector class</p> <pre><code> class ConnectionDetector { private Context _context; public ConnectionDetector(Context context){ this._context = context; } public boolean isConnectingToInternet(){ ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) for (int i = 0; i &lt; info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload