Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
c6657efb
U
uni-api
项目概览
DCloud
/
uni-api
通知
697
Star
23
Fork
13
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c6657efb
编写于
10月 30, 2023
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
开源:uni.getNetworkType
上级
f4f3504a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
271 addition
and
0 deletion
+271
-0
uni_modules/uni-getNetworkType/changelog.md
uni_modules/uni-getNetworkType/changelog.md
+0
-0
uni_modules/uni-getNetworkType/package.json
uni_modules/uni-getNetworkType/package.json
+93
-0
uni_modules/uni-getNetworkType/readme.md
uni_modules/uni-getNetworkType/readme.md
+6
-0
uni_modules/uni-getNetworkType/utssdk/app-android/AndroidManifest.xml
...uni-getNetworkType/utssdk/app-android/AndroidManifest.xml
+7
-0
uni_modules/uni-getNetworkType/utssdk/app-android/index.uts
uni_modules/uni-getNetworkType/utssdk/app-android/index.uts
+102
-0
uni_modules/uni-getNetworkType/utssdk/app-ios/index.uts
uni_modules/uni-getNetworkType/utssdk/app-ios/index.uts
+0
-0
uni_modules/uni-getNetworkType/utssdk/interface.uts
uni_modules/uni-getNetworkType/utssdk/interface.uts
+63
-0
未找到文件。
uni_modules/uni-getNetworkType/changelog.md
0 → 100644
浏览文件 @
c6657efb
uni_modules/uni-getNetworkType/package.json
0 → 100644
浏览文件 @
c6657efb
{
"id"
:
"uni-getNetworkType"
,
"displayName"
:
"uni-getNetworkType"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-getNetworkType"
,
"keywords"
:
[
"uni-getNetworkType"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.6.8"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"uni-ext-api"
:
{
"uni"
:
{
"getNetworkType"
:
{
"name"
:
"getNetworkType"
,
"app"
:
{
"js"
:
false
,
"kotlin"
:
true
,
"swift"
:
false
}
}
}
},
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-getNetworkType/readme.md
0 → 100644
浏览文件 @
c6657efb
# uni-getNetworkType
### 开发文档
[
UTS 语法
](
https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html
)
[
UTS API插件
](
https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
)
[
UTS 组件插件
](
https://uniapp.dcloud.net.cn/plugin/uts-component.html
)
[
Hello UTS
](
https://gitcode.net/dcloud/hello-uts
)
\ No newline at end of file
uni_modules/uni-getNetworkType/utssdk/app-android/AndroidManifest.xml
0 → 100644
浏览文件 @
c6657efb
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
package=
"io.dcloud.uni.getNetworkType"
>
<!--permissions-->
<!-- 访问网络状态 -->
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
</manifest>
uni_modules/uni-getNetworkType/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
c6657efb
import { GetNetworkTypeOptions, GetNetworkType, GetNetworkTypeSuccess } from "../interface.uts";
import UTSAndroid from 'io.dcloud.uts.UTSAndroid';
import Context from 'android.content.Context';
import ConnectivityManager from 'android.net.ConnectivityManager';
import TelephonyManager from 'android.telephony.TelephonyManager';
import Build from 'android.os.Build';
export const getNetworkType : GetNetworkType = function (options : GetNetworkTypeOptions) {
const context = UTSAndroid.getUniActivity()!!;
const connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager;
if (connectivityManager != null) {
if (Build.VERSION.SDK_INT >= 23) {
const permissions = ["android.permission.ACCESS_NETWORK_STATE"];
if (!UTSAndroid.checkSystemPermissionGranted(context, permissions)) {
const result : GetNetworkTypeSuccess = {
networkType: "none"
}
options?.success?.(result);
options?.complete?.(result);
return
}
}
const activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo != null) {
if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
const result : GetNetworkTypeSuccess = {
networkType: "wifi"
}
options?.success?.(result);
options?.complete?.(result);
} else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
let type = "unknown";
const subtype = activeNetworkInfo.getSubtype();
switch (subtype) {
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_GPRS:
case 7://电信2g 努比亚
type = "2g";
break;
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case 12://level9以上支持 TelephonyManager.NETWORK_TYPE_EVDO_B = 12
case 14://电信 努比亚
//3G 电信
type = "3g";
break;
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_UMTS:
//3G 联通
type = "3g";
break;
case 17:
case 18:
//3G 移动(目前华为系统切换到3g时候为此值)
type = "3g";
break;
case 13: //level11 以上支持TelephonyManager.NETWORK_TYPE_LTE = 13
case 11: //level8以上支持TelephonyManager.NETWORK_TYPE_IDEN=11
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case 15://stype == TelephonyManager.NETWORK_TYPE_HSPAP
type = "4g";
break;
case TelephonyManager.NETWORK_TYPE_NR: {
type = "5g";
break;
}
default://对于case之外的反馈到js,js层收集之后回馈5+进行填补完善
type = "" + subtype;
break;
}
const result : GetNetworkTypeSuccess = {
networkType: type
}
options?.success?.(result);
options?.complete?.(result);
} else {
const result : GetNetworkTypeSuccess = {
networkType: "unknown"
}
options?.success?.(result);
options?.complete?.(result);
}
}else{
const result : GetNetworkTypeSuccess = {
networkType: "none"
}
options?.success?.(result);
options?.complete?.(result);
}
} else {
const result : GetNetworkTypeSuccess = {
networkType: "none"
}
options?.success?.(result);
options?.complete?.(result);
}
};
\ No newline at end of file
uni_modules/uni-getNetworkType/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
c6657efb
uni_modules/uni-getNetworkType/utssdk/interface.uts
0 → 100644
浏览文件 @
c6657efb
export interface Uni {
/**
* getNetworkType()
* @description
* 获取网络类型
* @param {GetNetworkTypeOptions} options
* @return {void}
* @tutorial http://uniapp.dcloud.io/api/system/network?id=getnetworktype
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4",
* "uniVer": "√",
* "unixVer": "3.9+"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
* @example
```typescript
uni.getNetworkType({
success(res){
console.log(res);
}
});
```
*/
getNetworkType(options: GetNetworkTypeOptions): void;
}
export type GetNetworkType = (options: GetNetworkTypeOptions) => void;
export type GetNetworkTypeSuccess = {
/**
* 网络类型
*/
networkType: string
};
export type GetNetworkTypeSuccessCallback = (result: GetNetworkTypeSuccess) => void;
export type GetNetworkTypeFail = UniError;
export type GetNetworkTypeFailCallback = (result: GetNetworkTypeFail) => void;
export type GetNetworkTypeComplete = any;
export type GetNetworkTypeCompleteCallback = (result: GetNetworkTypeComplete) => void;
export type GetNetworkTypeOptions = {
/**
* 接口调用成功的回调函数
* @defaultValue null
*/
success?: GetNetworkTypeSuccessCallback | null,
/**
* 接口调用失败的回调函数
* @defaultValue null
*/
fail?: GetNetworkTypeFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
* @defaultValue null
*/
complete?: GetNetworkTypeCompleteCallback | null
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录