Last active
December 16, 2019 03:06
-
-
Save taner-dll/6488330 to your computer and use it in GitHub Desktop.
Android - Check Internet Connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.animacoder.akcaykentportali; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.widget.Toast; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ConnectivityManager connMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); | |
if (networkInfo != null && networkInfo.isConnected()) | |
{ | |
Toast.makeText(MainActivity.this,"Baglanti basarili",2000).show(); | |
Thread t1 = new Thread() | |
{ | |
public void run() | |
{ | |
try | |
{ | |
sleep(1000); | |
Intent intent = new Intent(MainActivity.this, DashboardActivity.class); | |
startActivity(intent); | |
} | |
catch (InterruptedException e){} | |
finally{finish();} | |
} | |
}; | |
t1.start(); | |
} | |
else | |
{ | |
Toast.makeText(MainActivity.this,"Lutfen internet baglantinizi kontrol edin.",2000).show(); | |
Toast.makeText(MainActivity.this,"Kapatılıyor...",2000).show(); | |
Thread t2 = new Thread() | |
{ | |
public void run() | |
{ | |
try | |
{ | |
sleep(2000); | |
finish(); | |
} | |
catch (InterruptedException e){} | |
finally{finish();} | |
} | |
}; | |
t2.start(); | |
} | |
}; | |
@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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment