zoukankan      html  css  js  c++  java
  • android 判断网络状态

    <uses-permission  android:name="android.permission.ACCESS_NETWORK_STATE" />  
     
    private boolean getNetWorkStatus() {  
     
       boolean netSataus = false;  
       ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);  
     
       cwjManager.getActiveNetworkInfo();  
     
       if (cwjManager.getActiveNetworkInfo() != null) {  
           netSataus = cwjManager.getActiveNetworkInfo().isAvailable();  
       }  
     
       if (!netSataus) {  
           Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络")  
               .setMessage("是否对网络进行设置?");  
           b.setPositiveButton("是", new DialogInterface.OnClickListener() {  
               public void onClick(DialogInterface dialog, int whichButton) {  
                   Intent mIntent = new Intent("/");  
                   ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");  
                   mIntent.setComponent(comp);  
                   mIntent.setAction("android.intent.action.VIEW");  
                   startActivityForResult(mIntent,0);   
               }  
           }).setNeutralButton("否", new DialogInterface.OnClickListener() {  
               public void onClick(DialogInterface dialog, int whichButton) {  
                   dialog.cancel();  
              }  
           }).show();  
       }  
       return netSataus;  
    }
  • 相关阅读:
    vue 初始化项目模板报错
    092117-6265-01.dmp 蓝屏日志文件
    电信流氓注入JS
    DISM
    node.js
    Adobe ZXPInstaller 报错 Installation failed because of a file operation error.
    Microsoft Edge 针对 Web 开发人员更新日志
    What's new in Safari 11.0
    CSS Filter
    accept-language
  • 原文地址:https://www.cnblogs.com/miaozhenzhong/p/5931044.html
Copyright © 2011-2022 走看看