获取设备信息&应用信息&监听网络&打开第三方APP
获取设备信息 device_info_plus
import 'package:device_info_plus/device_info_plus.dart';
final deviceInfoPlugin = DeviceInfoPlugin();
final deviceInfo = await deviceInfoPlugin.deviceInfo;
final deviceInfoMap = deviceInfo.toMap().entries /* MAP格式的设备信息*/
监听网络 connectivity_plus
import 'package:connectivity_plus/connectivity_plus.dart';
dynamic subscription;
initState(){
subscription = Connectivity()
.onConnectivityChanged
.listen((ConnectivityResult result){
if(result === ConnectivityResult.wifi){处于wifi}
else if(result == ConnectivityResult.mobile){处于手机网络}
else {没有网络}
})
}
获取应用信息
import 'package:package_info_plus/package_info_plus.dart';
/* 获取应用版本 */
getAppInfo()async{
PackageInfo packageInfo = await PackageInfo.fromPlatform();
print(packageInfo);
/*
* 常用配置
* appName 应用程序
* version 应用版本号
* packageName 应用程序的唯一标识符
*/
}
打开第三方APP
Android 配置
android\app\src\main\AndroidManifest.xml
<queries>
<!-- If your app checks for SMS support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<!-- If your app checks for call support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
IOS配置 Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>iosamap</string>
<string>baidumap</string>
<string>sms</string>
<string>tel</string>
<string>weixin</string>
<string>alipays</string>
</array>
使用
ElevatedButton(
onPressed:()async{
final Uri tel = Uri.parse('tel:10086');
if(await canLaunchUrl(tel)){
await launchUrl(tel)
}else{
throw "打不开 $tel"
}
}
)
打开第三方APP 参看之前总结的scheme表