You can create method and call it in mainactivity Connection con = new Connection(); con.methodname();
private fun checkConnectivity(){ val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetwork = cm.activeNetworkInfo val isConnected = activeNetwork != null && activeNetwork.isConnected if (!isConnected){ // Not Connected }else{ Log.d("internet", "Connected to internet") val isWifi = activeNetwork.type if (isWifi == ConnectivityManager.TYPE_WIFI){ }else{ Toast.makeText(this,"Running on Mobile Data",Toast.LENGTH_LONG).show() } } } this is in kotlin but the working is same you will get a hint
Обсуждают сегодня