in Education by
Please see the code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); receiverWifi = new WifiReceiver(); mIntentFilter = new IntentFilter(); final IntentFilter mIFNetwork = new IntentFilter(); mIFNetwork.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION); //"android.net.conn.CONNECTIVITY_CHANGE" registerReceiver(receiverWifi, mIFNetwork); // mainWifi.startScan(); haveNetworkConnection() ; }// end of the function and class WifiReceiver extends BroadcastReceiver { public void onReceive(Context c, Intent intent) { // Toast.makeText(SecondActivity.this, "Message is show", Toast.LENGTH_LONG).show(); // haveNetworkConnection() ; boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); if (noConnectivity) { ImageButton b=(ImageButton)findViewById(R.id.button4); b.setBackgroundResource(R.drawable.lightedbutton_off); } else { ImageButton b=(ImageButton)findViewById(R.id.button4); b.setBackgroundResource(R.drawable.lightedbutton_on); } }// } i want to on the button when only device is connected with wifi , but using above code condition becomes true if device is also connected with edge/gprs Please how can I do this JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I use this code to check Wifi and mobile network connection also, public boolean isOnline(Context context) { boolean state=false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null) { state=wifiNetwork.isConnectedOrConnecting(); System.out.println("wifiNetwork.isAvailable(): "+wifiNetwork.isAvailable()); System.out.println("wifiNetwork.isConnected(): "+wifiNetwork.isConnected()); System.out.println("wifiNetwork.isFaileOver(): "+wifiNetwork.isFailover()); System.out.println("wifiNetwork.isConnectedOrConnecting: "+state); } NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null) { state=mobileNetwork.isConnectedOrConnecting(); } NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) { state=activeNetwork.isConnectedOrConnecting(); } return state; }

Related questions

0 votes
    Please see the code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Please see the code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Please see the code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I've noticed on Marshmallow (e.g. Nexus 6P) and also on some more recently updated Lollipop phones ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have an app that needs to be connected to a specific network. I already have a code to force ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have an app that needs to be connected to a specific network. I already have a code to force ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I am seeking an Android solution to calculate the distance to an object and then determine the size (height ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have an application that uses FCM to receive messages from a custom server. There are some situations ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I would like to detect the presence of unsecured wifi network in my app. Is there any public iOS ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I would like to detect the presence of unsecured wifi network in my app. Is there any public iOS ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Hints: Peers,Hub,WiFi,Layout, Repeater 1) A dash is a central controller device in a network 2) A dash ... other are called dash Select the correct answer from above options...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    I'm looking at making an custom Android object Serializable. Should be simple I just cannot find a easy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    Here some snippet of my code. when first time RecyclerView create I have to used recyclerView.scrollToPosition( ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I want making multi-bluetooth from Android studio. I found multi-bluetooth java code libraries. but I am ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    Let's say I have this variable: long myMillis = 20000; This means that I want my Chronometer to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
...