【React Native】在网页中打开Android应用程序
React Native官方提供Linking库用于调起其他app或者本机应用。Linking的主要属性和方法有:
属性与方法
canOpenURL(url); 判断设备上是否有已经安装相应应用或可以处理URL的程序,本方法会返回一个Promise对象,只有一个回调参数,格式为Boolean值。
openURL(url); 打开设备上的某个应用或可以处理URL的程序,本方法会返回一个Promise对象。
addEventListener(type, handler); 添加一个监听 Linking 变化的事件。type 参数应填'url',并提供一个处理函数。
removeEventListener(type, handler); 删除一个事件处理函数。type 参数应填'url'。
getInitialURL(); 如果应用是被一个链接调起的,则会返回相应的链接地址。否则它会返回null。
使用
// 在调起其他app或者本机应用前先检查是否已经安装:
Linking.canOpenURL('weixin://').then(supported => {
if (!supported) {
console.log('无法处理该URL:' + url);
} else {
return Linking.openURL('weixin://');
}
}).catch(err => console.error('错误:', err)); // 本应用被其注册过的外部url调起
Linking.getInitialURL().then(url => {
if (url) {
console.log('本app被其它应用调起:' + url);
}
}).catch(err => {
console.warn('错误:', err);
}); // 监听Linking的相关事件
Linking.addEventListener('url', this._handleOpenURL); // 移除Linking的相关事件
Linking.removeEventListener('url', this._handleOpenURL); _handleOpenURL(event) {
console.log(event.url);
android自定义URL Scheme:
android/app/src/main/AndroidManifest.xml文件,配置如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.auth">
... <application
...
android:launchMode="singleTask" // 新增1
...
<activity
...
// 新增2
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="auth" />
</intent-filter>
</activity>
...
</application> </manifest>
【React Native】在网页中打开Android应用程序的更多相关文章
- WEB通知和React Native之即时通讯(iOS Android)
WEB通知和React Native之即时通讯(iOS Android) 一,需求分析 1.1,允许服务器主动发送信息给客户端,客户端能监听到并且能接收. 1.2,为了方便同一个系统内的用户可以指定某 ...
- React Native之通知栏消息提示(android)
React Native之通知栏消息提示(android) 一,需求分析与概述 1.1,推送作为手机应用的基本功能,是手机应用的重要部分,如果自己实现一套推送系统费时费力,所以大部分的应用都会选择使用 ...
- React Native之微信分享(iOS Android)
React Native之微信分享(iOS Android) 在使用React Native开发项目的时候,基本都会使用到微信好友或者微信朋友圈分享功能吧,那么今天我就带大家实现以下RN微信好友以及朋 ...
- React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)
React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...
- 在Android Studio中打开Android Device Monitor时报错的解决方法
在Android Studio中打开Android Device Monitor时报以下错误时(Android-SDK\tools\lib\monitor-x86_64\configuration\1 ...
- React Native 真机调试(iOS / Android)
React Native 真机调试(iOS / Android) https://reactnative.dev/docs/running-on-device https://developer.ap ...
- 通过浏览器直接打开Android应用程序
需求 通过手机浏览器直接打开Android应用程序.假设本地已经安装了指定Android应用,就直接打开它:假设没有安装,则直接下载该应用的安装文件(也能够跳转到下载页面). 实现效果 假设手机上已经 ...
- js网页中调用本地应用程序
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv="Con ...
- iOS评分功能、APP中打开其他应用程序
1.评分功能 iOS中评分支持功能开发非常简单. NSString *str = [NSString stringWithFormat: @"itms-apps://itunes.apple ...
随机推荐
- 英语学习app——Alpha发布2
英语学习app--Alpha发布1 这个作业属这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ ...
- 龙芯 Fedora 28 设置 VNC
系统为龙芯版Fedora28 (床28) Fedora防火墙默认阻止了VNC所需的端口的访问,导致VNC客户端一直无法连接. 安装VNC Server sudo dnf install tigervn ...
- 同一个环境同时使用python2和python3的方法
1.首先安装好p2和p3,配置好环境变量.在CMD内执行python返回版本号,返回结果根据配置的环境变量而定,如果p2的环境变量配置在前面,则返回p2的版本号,反之则p3 2.然后把各版本目录下的p ...
- Spring中的BeanPostProcessor详解
Spring中的BeanPostProcessor详解 概述 BeanPostProcessor也称为Bean后置处理器,它是Spring中定义的接口,在Spring容器的创建过程中(具体为Bean初 ...
- 如何更改cmd 编码为UTF-8
如何将cmd编码改为UTF—8 如图输入chcp 65001即可更改 改完之后是这样的 更改回GBK 输入 CHCP 936即可
- HanLP《自然语言处理入门》笔记--5.感知机模型与序列标注
笔记转载于GitHub项目:https://github.com/NLP-LOVE/Introduction-NLP 5. 感知机分类与序列标注 第4章我们利用隐马尔可夫模型实现了第一个基于序列标注的 ...
- 【阿里云IoT+YF3300】13.阿里云IoT Studio WEB监控界面构建
Web可视化开发是阿里云IoT Studio中比较重要的一个功能,通过可视化拖拽的方式,方便地将各种图表组件与设备相关的数据源关联,无需编程,即可将物联网平台上接入的设备数据可视化展现. 目前支持的组 ...
- Java入门基础(类)
类 在Java中表示自定义的数据类型,一个class可以是若干基本类型的组合. public class Student { public String id;//学号 public String n ...
- HDU_3410_单调栈
http://acm.hdu.edu.cn/showproblem.php?pid=3410 初探单调栈,从左往右,求l,从右往左,求r. #include<iostream> #incl ...
- Codeforces_490_E
http://codeforces.com/problemset/problem/490/E dfs,过程要注意细节,特别是当前位置取了与上个数当前位置相同是,若后面不符合条件,则当前位置要重置'?' ...