小贴士1

来源:互联网 发布:电机pid控制算法 编辑:程序博客网 时间:2024/05/03 13:45

1.获取mac地址

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

 2.全屏
一是在代码中设置,另一种方法是在配置文件里改!

一、在代码中设置:

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //无title   requestWindowFeature(Window.FEATURE_NO_TITLE);   //全屏   getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,     WindowManager.LayoutParams. FLAG_FULLSCREEN);          setContentView(R.layout.main); } } 

设置全屏的俩段代码必须在setContentView(R.layout.main) 之前,不然会报错。

二、在配置文件里修改(android:theme="@android:style/Theme.NoTitleBar.Fullscreen"):


3、网络状态

<uses-permissionandroid: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;    }


原创粉丝点击