android程序中实现打开另一个app
1、已知要打开的apk的包名
String packetName = "com.onedollar.smartnurse"; Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(packetName); // 这里如果intent为空,就说名没有安装要跳转的应用 if (intent != null) {if (!getActivity().getPackageName().equals(packetName)) {startActivity(intent);} else {ToastView.showToast("你已经在当前应用中");} } else {//打开应用市场Uri uri = Uri.parse("market://details?id=" + packetName);intent = new Intent(Intent.ACTION_VIEW, uri);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);try {getActivity().startActivity(intent);} catch (Exception e) {ToastView.showToast("打开应用市场失败");} }
2.配置scheme和host
在AndroidManifest.xml文件中,为要启动的页面配置过滤器,添加如下代码:
<intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><dataandroid:host="DaMeiShangRao"android:scheme="DangZheng" /> </intent-filter>
如果是启动Activity,不能把原来的过滤器覆盖掉,及在原因过滤下添加上述代码
<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><dataandroid:host="test"android:scheme="myapp" /></intent-filter>
在activtity中通过uri调用该页面,uri的组成为[scheme]://[host]
Uri uri=Uri.parse("myapp://test");Intent intent= new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);
配置scheme和host后,可以在浏览器通过点击链接打开客户端 <a href="myapp://test" >打开客户端</a>
注意:scheme和host必须小写
转载于:https://www.cnblogs.com/3A87/p/4867604.html
android程序中实现打开另一个app相关推荐
- android另开进程,android在一个app程序中,打开另一个app的方法
使用aapt //aapt是sdk自带的一个工具,在sdk\builds-tools\目录下 1.以微信为例,命令行中切换到aapt.exe目录执行:aapt dump badging E:\a ...
- android读取另一个app目录,android在一个app程序中,打开另一个app的方法
首先获取包名: 使用aapt //aapt是sdk自带的一个工具,在sdk\builds-tools\目录下 1.以微信为例,命令行中切换到aapt.exe目录执行:aapt dump badg ...
- android点击另一个app,Android 怎么从一个APP中打开另外一个APP
Android 如何从一个APP中打开另外一个APP 众所周知,在一个APP内部,从一个页面跳转到另外一个页面是使用startactivity函数来实现的. 同样的,对于应用之间的跳转也是如此的.应用 ...
- Android在app中打开另一个app
打开另一个app 知道包名和MainActivity类名之后 Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(In ...
- android 打开其它app,Android 在一个APP里打开另一个APP
前言 不知道你们有没有注意过,每次打开一些软件的时候都会有广告引导页,有时候手滑点到了,会有进入手机上的另一个APP,这有没有引起你的注意呢? 运行效果图 正文 为了测试这个功能,首先要创建两个项目, ...
- Android 在app里面打开另一个app,加<uses-permission android:name=“android.permission.QUERY_ALL_PACKAGES“
Android 在app里面打开另一个app 一.方式1:打开外部app,在新窗口打开. //打开外部app,新窗口打开private void doStartApplicationWithPacka ...
- Android程序中读取使用已有的SQLite数据库
方法一: 先在 Manifest 里添加权限: [java] view plaincopy print? <span style="font-size:12px;">& ...
- 将uni-app打包的H5放在 Android程序中在 webview 显示的两种方法
将uni-app打包的H5放在 Android程序中在 webview 显示的两种方法 前言 Hash History 完事 前言 之前有个项目要同时做小程序和APP,本着节省时间的想法,研究了下un ...
- android动画view上移,在Android开发中使用View制作一个引导动画
在Android开发中使用View制作一个引导动画 发布时间:2020-11-20 16:46:16 来源:亿速云 阅读:98 作者:Leah 这篇文章将为大家详细讲解有关在Android开发中使用V ...
最新文章
- Dictionary (Of (TKey, TValue)) Class Example
- Java获取运行环境信息
- AngularJs 抓狂之: $q promise 自动unwarp功能被禁用了
- 小程序 video 控制器外观调整_最好的Nintendo Switch控制器
- PHP的pcntl多进程
- java_IO总结(一)
- 正则表达式re.S的用法
- Hue中Sqoop导数报错Could not load db driver class: com.mysql.jdbc.Driver
- python3 tkinter 桌面软件教程
- hdu1048(c++)
- 操作系统原理课程 期末考试复习重点
- SQL基础系列(八)——排序、分组排序(RANK)
- 如何用树莓派借用计算机的显示屏,树莓派4寸A显示屏使用教程
- Windows Sockets概述
- streamx编译,streamx-console初始化启动踩坑
- 治疗性经颅磁刺激后大规模脑电图神经网络的变化
- 手工折纸作品展示:送别的花束
- 亿赛通喜获 “2015年度中国软件和信息服务数据安全领域杰出企业奖”
- `Computer-Algorithm` 有向无环图DAG
- val什么意思vb中的属性值_VB: ByVal是什么意思