| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.net.ConnectivityManager; |
| | | import android.net.NetworkInfo; |
| | | import android.os.IBinder; |
| | | |
| | | import cn.com.basic.face.discern.entity.Device; |
| | | import cn.com.basic.face.service.ConnetedService; |
| | | import cn.com.basic.face.service.DictionaryMng; |
| | | import cn.com.basic.face.service.DeviceMng; |
| | | import cn.com.basic.face.util.WindowsUtil; |
| | |
| | | OkHttpUtils.init(this); |
| | | } |
| | | |
| | | boolean isConnect = false; |
| | | boolean flag = false; |
| | | |
| | | // |
| | | private ConnetedService.MyBinder myBinder; |
| | | |
| | | |
| | | private ServiceConnection conn=new ServiceConnection() { |
| | | |
| | | @Override |
| | | public void onServiceDisconnected(ComponentName arg0) { |
| | | myBinder=null; |
| | | |
| | | public boolean networkNotAvailable() { |
| | | boolean connected = false; |
| | | ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || |
| | | connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) { |
| | | connected = true; |
| | | } |
| | | |
| | | @Override |
| | | public void onServiceConnected(ComponentName arg0, IBinder service) { |
| | | myBinder=(ConnetedService.MyBinder) service; |
| | | } |
| | | }; |
| | | |
| | | public void bindService(){ |
| | | isConnect = true; |
| | | flag=true; |
| | | Intent intent=new Intent(application,ConnetedService.class); |
| | | application.bindService(intent, conn, Context.BIND_AUTO_CREATE); |
| | | return !connected; |
| | | } |
| | | |
| | | public boolean networkAvailable() { |
| | | boolean connected = false; |
| | | ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || |
| | | connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) { |
| | | connected = true; |
| | | } |
| | | return connected; |
| | | } |
| | | |
| | | |
| | | } |