то, что я сделал этокод работы, когда Wi-Fi выключен и 3G включен, но не тогда, когда wifioff и 4G
я играю в поток WiFi и 3g также на. Я отключил Wi-Fi, остановил поток, но перезапустил его, чтобы активировать 3g.
Но проблема начинается тогда, когда Wi-Fi и 4g на, что время ее не работает
я добавил слушатель как
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(receiver,intentFilter) ;
и приемником
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try{ {
if(GetNetworkStatus.isNetworkAvailable(getApplicationContext()))
{if(!mIsPlaying)
justPlay();
}
else
{justStop();
handler=new Handler();
r = new Runnable()
{
public void run()
{
try{
Thread.sleep(4000);
}
catch(Exception s)
{}
if(GetNetworkStatus.isNetworkAvailable(getApplicationContext()))
justPlay();
/*if(!mIsPlaying)
handler.postDelayed(this, 3000);*/
}
};
try{
handler.postDelayed(r, 1000);
}
catch(Exception e)
{
}
Toast.makeText(getApplicationContext(), "Internet Connection Failed", Toast.LENGTH_LONG).show();
}
}
}
catch(Exception e)
{
finish();
} }
};
GetNetworkStatus.isNetworkAvailable() код публичный статический логический isNetworkAvailable (контекст Context) { \t \t CON = контекст; \t \t ConnectivityManager connectManManager \t = (ConnectivityManager) con.getSystemService (Context.CONNECTIVITY_SERVICE); \t NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); \t return activeNetworkInfo! = Null; \t} –
не могли бы вы проверить мой обновленный ответ? –