初始化
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "21"
|
||||
}
|
||||
27
uni_modules/uts-openSchema/utssdk/app-android/index.uts
Normal file
27
uni_modules/uts-openSchema/utssdk/app-android/index.uts
Normal file
@@ -0,0 +1,27 @@
|
||||
import Intent from 'android.content.Intent'
|
||||
import Uri from 'android.net.Uri'
|
||||
import { OpenSchema, CanOpenURL } from '../interface.uts'
|
||||
|
||||
export const openSchema : OpenSchema = function (url : string) {
|
||||
if (canOpenURL(url)) {
|
||||
const context = UTSAndroid.getUniActivity()!
|
||||
const uri = Uri.parse(url)
|
||||
const intent = new Intent(Intent.ACTION_VIEW, uri)
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.setData(uri)
|
||||
context.startActivity(intent)
|
||||
} else {
|
||||
console.error('url param Error:', JSON.stringify(url))
|
||||
}
|
||||
}
|
||||
|
||||
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
|
||||
if (typeof url === 'string' && url.length > 0) {
|
||||
const context = UTSAndroid.getUniActivity()!
|
||||
const uri = Uri.parse(url)
|
||||
const intent = new Intent(Intent.ACTION_VIEW, uri)
|
||||
return intent.resolveActivity(context.packageManager) != null ? true : false
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
20
uni_modules/uts-openSchema/utssdk/app-harmony/index.uts
Normal file
20
uni_modules/uts-openSchema/utssdk/app-harmony/index.uts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { bundleManager, common } from '@kit.AbilityKit';
|
||||
import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'
|
||||
import { getAbilityContext } from '@dcloudio/uni-runtime'
|
||||
import { OpenSchema, CanOpenURL } from '../interface.uts'
|
||||
|
||||
|
||||
export const openSchema : OpenSchema = function (url : string) : void {
|
||||
(getAbilityContext() as common.UIAbilityContext)?.openLink(url, {
|
||||
appLinkingOnly: false
|
||||
} as OpenLinkOptions)
|
||||
}
|
||||
|
||||
|
||||
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
|
||||
try {
|
||||
return bundleManager.canOpenLink(url)
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
3
uni_modules/uts-openSchema/utssdk/app-ios/config.json
Normal file
3
uni_modules/uts-openSchema/utssdk/app-ios/config.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "12.0"
|
||||
}
|
||||
20
uni_modules/uts-openSchema/utssdk/app-ios/index.uts
Normal file
20
uni_modules/uts-openSchema/utssdk/app-ios/index.uts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { OpenSchema, CanOpenURL } from '../interface.uts'
|
||||
|
||||
export const openSchema : OpenSchema = function (url : string) : void {
|
||||
if (canOpenURL(url)) {
|
||||
let uri = new URL(string = url)
|
||||
UIApplication.shared.open(uri!, options = new Map<UIApplication.OpenExternalURLOptionsKey, any>(), completionHandler = null)
|
||||
} else {
|
||||
console.error('url param Error: ', url)
|
||||
}
|
||||
}
|
||||
|
||||
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
|
||||
if (typeof url == 'string' && url.length > 0) {
|
||||
let uri = new URL(string = url)
|
||||
if (uri != null && UIApplication.shared.canOpenURL(uri!)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
2
uni_modules/uts-openSchema/utssdk/interface.uts
Normal file
2
uni_modules/uts-openSchema/utssdk/interface.uts
Normal file
@@ -0,0 +1,2 @@
|
||||
export type OpenSchema = (url : string) => void
|
||||
export type CanOpenURL = (url : string) => boolean
|
||||
12
uni_modules/uts-openSchema/utssdk/web/index.uts
Normal file
12
uni_modules/uts-openSchema/utssdk/web/index.uts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { OpenSchema, CanOpenURL } from '../interface.uts'
|
||||
|
||||
export const openSchema : OpenSchema = function (url : string) : void {
|
||||
location.href = url;
|
||||
}
|
||||
|
||||
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
|
||||
if (url != "") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user