zoukankan      html  css  js  c++  java
  • Activity常用知识

      1.获取系统语言设置

    String str = Locale.getDefault().getLanguage();

    系统语言改变发送广播
    filter = new IntentFilter("Intent.ACTION_LOCALE_CHANGED");

      2.获得系统电量

    public class LowerPowerReceiver extends BroadcastReceiver
    {
    
        @Override
        public void onReceive(Context context, Intent intent)
        {
            // TODO Auto-generated method stub
            if(Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction()))
            {
                //当前电量
                int level = intent.getIntExtra("level", 0);
                //电量总刻度
                int scale = intent.getIntExtra("scale", 100);
                //电池电量
                float a = level*100.0f/scale;
                Toast.makeText(context, "电量为:"+a+"%", Toast.LENGTH_SHORT).show();
            }
            if(Intent.ACTION_BATTERY_LOW.equals(intent.getAction()))
            {
                Toast.makeText(context, "电量过低,请及时充电", Toast.LENGTH_SHORT).show();
            }
            if(Intent.ACTION_BATTERY_OKAY.equals(intent.getAction()))
            {
                Toast.makeText(context, "电量已满,请拔出充电器", Toast.LENGTH_SHORT).show();
            }
    
        }
    
    }


     3. 获得MAC

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  
    private String getLocalMacAddress() {
        WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        return info.getMacAddress();
      }

    4. 获得网络状态

     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;
        }
        
  • 相关阅读:
    针对小程序for循环绑定数据,实现toggle切换效果(交流QQ群:604788754)
    小程序中bindtap绑定函数,函数参数event对数据的处理
    小程序中data数据的处理方法总结(小程序交流群:604788754)
    Power OFF and ON USB device in linux (ubuntu)
    linux控制USB的绑定/解绑
    卡内操作系统COS
    Linux内核:sk_buff解析
    skb_store_bits() 和 skb_copy_bits()
    skb详细解析【转】
    TCP:WireShark分析,序列号Seq和确认号Ack
  • 原文地址:https://www.cnblogs.com/xilinch/p/2617134.html
Copyright © 2011-2022 走看看