Skip to content

Instantly share code, notes, and snippets.

@melihmucuk
Created October 1, 2013 21:57
Show Gist options
  • Save melihmucuk/6785793 to your computer and use it in GitHub Desktop.
Save melihmucuk/6785793 to your computer and use it in GitHub Desktop.
Checking Internet and GPS status on Android
if(internetErisimi()){
{
startActivity(new Intent (BaslangicSayfasi.this,AnaSayfa.class));
}
}
else{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setMessage("Uygulamayı kullanabilmek için internet bağlantınızın aktif olması gerekmektedir");
alertDialog.setButton("Tamam", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
alertDialog.show();
}
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
public boolean internetErisimi(){
ConnectivityManager baglanti = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if(baglanti.getActiveNetworkInfo()!=null){
if(baglanti.getActiveNetworkInfo().isConnected ())
return true;
}
return false;
}
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public void kontrol(){
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
if(internetErisimi()){
{
startActivity(new Intent (BaslangicSayfasi.this,Anasayfa.class));
}
}
else{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setMessage("Uygulamayı kullanabilmek için internet bağlantınızın aktif olması gerekmektedir");
alertDialog.setButton("Tamam", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
alertDialog.show();
}
}
else{
AlertDialog alertDialog2 = new AlertDialog.Builder(this).create();
alertDialog2.setMessage("Uygulamayı kullanabilmek için GPS'in aktif olması gerekmektedir");
alertDialog2.setButton("Tamam", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
alertDialog2.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment