本文整理自网络,侵删。
//记得设置给检测网络状态的权限uses Androidapi.JNIBridge, Androidapi.Helpers, Androidapi.JNI.JavaTypes, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Interfaces;
procedure TForm1.Button1Click(Sender: TObject);var ConnectivityManagerObj: JObject; ConnectivityManager: JConnectivityManager; NetworkInfo: JNetworkInfo; NetworkType: Integer;begin ConnectivityManagerObj := SharedActivityContext.getSystemService (TJContext.JavaClass.CONNECTIVITY_SERVICE); ConnectivityManager := TJConnectivityManager.Wrap ((ConnectivityManagerObj as ILocalObject).GetObjectID);
NetworkInfo := ConnectivityManager.getActiveNetworkInfo(); if NetworkInfo = nil then begin ShowMessage('未接?A'); Exit; end;
NetworkType := NetworkInfo.getType; if NetworkType = TJConnectivityManager.JavaClass.TYPE_WIFI then begin ShowMessage('Wi-Fi数据通信'); end else if NetworkType = TJConnectivityManager.JavaClass.TYPE_MOBILE then begin ShowMessage('移动数据通信'); end;end;
相关阅读 >>
Delphi 利用createservice写与桌面交互的win32服务
Delphi一个非常完整的取windows os 版本信息的函数
Delphi xe firemonkey的stylebook皮肤控件的使用
Delphi 10.3.x 截取字符串函数substring 和copy()常用字串符处理函数用法
Delphi xe6 通过javascript api调用百度地图
更多相关阅读请进入《Delphi》频道 >>