index.uts 926 字节
Newer Older
D
DCloud_LXH 已提交
1 2
import Intent from 'android.content.Intent'
import Uri from 'android.net.Uri'
3
import { OpenSchema, CanOpenURL } from '../interface.uts'
D
DCloud_LXH 已提交
4

5 6
export const openSchema : OpenSchema = function (url : string) {
  if (canOpenURL(url)) {
D
DCloud_LXH 已提交
7 8 9
    const context = UTSAndroid.getUniActivity()!
    const uri = Uri.parse(url)
    const intent = new Intent(Intent.ACTION_VIEW, uri)
VK1688's avatar
VK1688 已提交
10
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
D
DCloud_LXH 已提交
11 12 13
    intent.setData(uri)
    context.startActivity(intent)
  } else {
14 15 16 17
    console.error('url param Error:', JSON.stringify(url))
  }
}

VK1688's avatar
VK1688 已提交
18
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
19 20 21 22
  if (typeof url === 'string' && url.length > 0) {
    const context = UTSAndroid.getUniActivity()!
    const uri = Uri.parse(url)
    const intent = new Intent(Intent.ACTION_VIEW, uri)
VK1688's avatar
VK1688 已提交
23
    return intent.resolveActivity(context.packageManager) != null ? true : false
24 25
  } else {
    return false
D
DCloud_LXH 已提交
26 27
  }
}