Android: How to check if Google is available?

后端 未结 3 918
甜味超标
甜味超标 2021-01-22 12:53

Can someone provide better and faster way to check if Google is available in Android? I have observed that connectiontimeout doesnot stop in given time_out. rather it takes more

3条回答
  •  迷失自我
    2021-01-22 13:20

    A broadcast receiver might come handy:

    BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {
    
            @Override
            public void onReceive(Context context, Intent intent) {
                Toast.makeText(getActivity(), "Connection reset, rolling back", Toast.LENGTH_LONG).show();
    
            }
        };
    

    It is also battery friendly.

    Also dont forget to unregister it: (onDestroy())

    getActivity().unregisterReceiver(networkStateReceiver);
    

提交回复
热议问题