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;
        }
        
  • 相关阅读:
    如何用Tensorflow训练模型成pb文件和和如何加载已经训练好的模型文件
    hbase rowkey 设计
    hbase集群region数量和大小的影响
    为什么不建议在hbase中使用过多的列簇
    hive explode 行拆列
    通过livy向CDH集群的spark提交任务
    case when多条件
    spark sql/hive小文件问题
    SQL join
    spark任务调度模式,动态资源分配
  • 原文地址:https://www.cnblogs.com/xilinch/p/2617134.html
Copyright © 2011-2022 走看看