0

I made an app that reads rss feeds, and I made a splash, and I would put inside the spash, I would put a function to check your internet connection, if the connection is present the app goes to Activity that reads rss feed if this is not the app displays a pop-up saying that the connection is absent and shows a button to close the app.

this is the code of my SplashActivity

code:

package rebus.palinsesti.tv;

import rebus.palinsesti.tv.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends Activity {

    private static String TAG = SplashActivity.class.getName();
    private static long SLEEP_TIME = 5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.splash);

        IntentLauncher launcher = new IntentLauncher();
        launcher.start();
    }

    private class IntentLauncher extends Thread {

        @Override
        public void run() {
            try {

                Thread.sleep(SLEEP_TIME*1000);
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }

            Intent intent = new Intent(SplashActivity.this, MainActivity.class);
            SplashActivity.this.startActivity(intent);
            SplashActivity.this.finish();
        }
    }

}
  • Possible duplicate of http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts – Qben Sep 04 '13 at 13:31
  • Splash screens are evil! http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/ – alex Sep 04 '13 at 13:41

2 Answers2

0
/**
 * Return Internet connection status
 * @param ctxt
 *      The context
 * @return
 *      True if internet is reachable
 *      False otherwise
 */
public boolean isInternetReachable(Context ctxt)
{
    ConnectivityManager cm = (ConnectivityManager) ctxt.getSystemService(Context.CONNECTIVITY_SERVICE);    
    android.net.NetworkInfo netInfo = cm.getActiveNetworkInfo();    
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

Try this one

Hope it helps

Skaard-Solo
  • 682
  • 6
  • 11
0
    This might help you:

      ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
                // ARE WE CONNECTED TO THE NET
                if (conMgr.getActiveNetworkInfo() != null
                        && conMgr.getActiveNetworkInfo().isAvailable()
                        && conMgr.getActiveNetworkInfo().isConnected()) {
//place the required operation here
    Toast.makeText(this, "net available", Toast.length_duration).show();
     }

    else
    Toast.makeText(this, "net not available", Toast.length_duration).show();
Harsh Parikh
  • 3,845
  • 3
  • 14
  • 14