-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
40 lines (33 loc) · 1.42 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ce.internet_kontrol;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
// bu projede import edilen nesnelerimiz aşağıda
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;
// import edilen nesneler bitiyor
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button kontrol = (Button) findViewById(R.id.kontrol);
kontrol.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(internet_kontrol())
Toast.makeText(MainActivity.this, "İnternet bağlantısı var - başarılı", Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "İnternet bağlantısı yok - başarısız", Toast.LENGTH_SHORT).show();
}
});
}
private boolean internet_kontrol() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
}
}