美文网首页
App常用状态获取

App常用状态获取

作者: OnlyRose | 来源:发表于2018-01-18 16:22 被阅读73次

    1.获取系统设置里面的响亮和振动是否使能

    Settings.System.getInt(Context mContext, "vibrate_when_ringing",0);
    

    2.获取系统当前网络制式

    int netWorkMode;
                    try {
                        netWorkMode = Settings.Secure.getInt(MainActivity.this.getContentResolver(), "preferred_network_mode");
                        System.err.println(netWorkMode);
                    } catch (SettingNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    

    3.获取移动数据开关状态

    public static boolean getMobileDataStatus(Context context)  
        {  
            String methodName = "getMobileDataEnabled";  
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            Class cmClass = mConnectivityManager.getClass();  
            Boolean isOpen = null;  
              
            try   
            {  
                Method method = cmClass.getMethod(methodName, null);  
      
                isOpen = (Boolean) method.invoke(mConnectivityManager, null);  
            }   
            catch (Exception e)   
            {  
                e.printStackTrace();  
            }  
            return isOpen;  
        }  
    

    相关文章

      网友评论

          本文标题:App常用状态获取

          本文链接:https://www.haomeiwen.com/subject/lfuwoxtx.html