Delphi XE7 判断Android应用程序中的通信状态类型


本文整理自网络,侵删。

 
//记得设置给检测网络状态的权限
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 取得dll所在目录

Delphi 利用createservice写与桌面交互的win32服务

Delphi一个非常完整的取windows os 版本信息的函数

Delphi xe firemonkey的stylebook皮肤控件的使用

Delphi实现百度地图经纬度与地址互转

Delphi 10.3.x 截取字符串函数substring 和copy()常用字串符处理函数用法

Delphi高亮显示trichedit当前行

Delphi posansi

Delphi wmi获取网卡mac

Delphi xe6 通过javascript api调用百度地图

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...