当前位置: 首页 > news >正文

Android之App跳转其他软件

文章目录

  • 前言
  • 一、效果图
  • 二、实现步骤
    • 1.弹框xml(自己替换图标)
    • 2.弹框utils
    • 3.两个弹框动画
    • 4.封装方便调用
    • 5.调用
    • 6.长按事件方法
    • 7.跳转步骤
    • 8.复制utils
  • 总结


前言

最近遇到一个需求,就是App内大面积需要长按复制并跳转指定App,没办法,只能埋头苦干呐,废话不多说,直接干!


一、效果图

在这里插入图片描述

二、实现步骤

1.弹框xml(自己替换图标)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:id="@+id/ll_share"android:layout_width="match_parent"android:layout_height="240dp"android:layout_alignParentBottom="true"android:background="@drawable/bzhs_bff_8"android:gravity="center_horizontal"android:orientation="vertical"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="24dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:text="@string/Pleaseselectanapp"android:textColor="#232323"android:textSize="16dp"android:textStyle="bold" /><ImageViewandroid:id="@+id/imag_gb"android:layout_width="39dp"android:layout_height="30dp"android:layout_alignParentRight="true"android:layout_marginRight="16dp"android:scaleType="center"android:src="@mipmap/ico_gban" /></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="20dp"android:layout_marginTop="41dp"android:layout_marginRight="20dp"android:layout_marginBottom="45dp"android:orientation="horizontal"><LinearLayoutandroid:id="@+id/cancle"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/telefram" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:text="Telegram"android:textColor="#232323"android:textSize="16dp"></TextView></LinearLayout><LinearLayoutandroid:id="@+id/confirm"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/whatsapp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:text="WhatsApp"android:textColor="#232323"android:textSize="16dp"></TextView></LinearLayout></LinearLayout></LinearLayout></RelativeLayout>

2.弹框utils

package com.example.merchant.utils;import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.TextView;import com.example.merchant.R;import java.util.Calendar;/*** Created by :caoliulang* ❤* Creation time :2023/9/01* ❤* Function :APP选择弹框*/
public class APPDialog extends Dialog {Context context;MenuListener mMenuListener;View mRootView;private Animation mShowAnim;private Animation mDismissAnim;private boolean isDismissing;LinearLayout cancle;//取消LinearLayout confirm;//确定ImageView imag_gb;//关闭public APPDialog(Context context) {super(context, R.style.ActionSheetDialog);this.context = context;getWindow().setGravity(Gravity.BOTTOM);initView(context);}private void initView(final Context context) {mRootView = View.inflate(context, R.layout.app_dialog, null);cancle = mRootView.findViewById(R.id.cancle);imag_gb=mRootView.findViewById(R.id.imag_gb);confirm = mRootView.findViewById(R.id.confirm);imag_gb.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {mMenuListener.onGb();}});confirm.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {mMenuListener.onSelect();}});cancle.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {cancel();}});this.setContentView(mRootView);initAnim(context);setOnCancelListener(new OnCancelListener() {@Overridepublic void onCancel(DialogInterface dialog) {if (mMenuListener != null) {mMenuListener.onCancel();}}});}private void initAnim(Context context) {mShowAnim = AnimationUtils.loadAnimation(context, R.anim.translate_up);mDismissAnim = AnimationUtils.loadAnimation(context, R.anim.translate_down);mDismissAnim.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {dismissMe();}@Overridepublic void onAnimationRepeat(Animation animation) {}});}@Overridepublic void show() {super.show();mRootView.startAnimation(mShowAnim);}@Overridepublic void dismiss() {if (isDismissing) {return;}isDismissing = true;mRootView.startAnimation(mDismissAnim);}private void dismissMe() {super.dismiss();isDismissing = false;}public MenuListener getMenuListener() {return mMenuListener;}public void setMenuListener(MenuListener menuListener) {mMenuListener = menuListener;}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_MENU) {dismiss();return true;}return super.onKeyDown(keyCode, event);}public interface MenuListener {void onCancel();void onSelect();void onGb();}
}

3.两个弹框动画

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"android:fromYDelta="100%"android:toYDelta="0"android:duration="250">
</translate>
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"android:fromYDelta="0%"android:toYDelta="100%"android:duration="250">
</translate>

4.封装方便调用

package com.example.merchant.utilsimport android.content.Context
import android.view.Window
import android.view.WindowManager
import com.example.merchant.R/*** @Author : CaoLiulang* @Time : 2023/9/27 14:42* @Description :*/
class AppTk {companion object {private lateinit var appDialog: APPDialog/*** app选择弹框*/fun showTimeDailog(message: String, context: Context) {appDialog = APPDialog(context)CopyUtils.copy(message, context)val window: Window = appDialog.window!!val lp = window.attributes//这句就是设置dialog横向满屏了。lp.width = WindowManager.LayoutParams.MATCH_PARENTlp.height = WindowManager.LayoutParams.WRAP_CONTENTwindow.attributes = lpappDialog.show()appDialog.setCanceledOnTouchOutside(false)appDialog.menuListener = object : APPDialog.MenuListener {//Telegramoverride fun onCancel() {if (appDialog != null) {appDialog.dismiss()//数据线连接设备命令输入adb shell pm list packages查看所有应用包名// 通过包名获取要跳转的app,创建intent对象val intent =context.packageManager.getLaunchIntentForPackage("org.telegram.messenger.web") // 这里如果intent为空,就说名没有安装要跳转的应用嘛if (intent != null) {// 这里跟Activity传递参数一样的嘛,不要担心怎么传递参数,还有接收参数也是跟Activity和Activity传参数一样context.startActivity(intent)} else {// 没有安装要跳转的app应用,提醒一下ToastUtils.showToast(context.resources.getString(R.string.Youhavenotinstalledthissoftwareyet))}}}//WhatsAppoverride fun onSelect() {if (appDialog != null) {appDialog.dismiss()//数据线连接设备命令输入adb shell pm list packages查看所有应用包名// 通过包名获取要跳转的app,创建intent对象val intent =context.packageManager.getLaunchIntentForPackage("com.whatsapp") // 这里如果intent为空,就说名没有安装要跳转的应用嘛if (intent != null) {// 这里跟Activity传递参数一样的嘛,不要担心怎么传递参数,还有接收参数也是跟Activity和Activity传参数一样context.startActivity(intent)} else {// 没有安装要跳转的app应用,提醒一下ToastUtils.showToast(context.resources.getString(R.string.Youhavenotinstalledthissoftwareyet))}}}override fun onGb() {appDialog.dismiss()}}}}
}

5.调用

AppTk.showTimeDailog(text.text.toString(),this)

6.长按事件方法

 //长按事件fun setCAListener(text: TextView) {text.setOnLongClickListener(View.OnLongClickListener {AppTk.showTimeDailog(text.text.toString(),this)true})}

7.跳转步骤

1:数据线连接设备,AS命令输入adb shell pm list packages查看所有应用包名

adb shell pm list packages

2:通过报名获取要跳转的app

 // 通过包名获取要跳转的app,创建intent对象val intent =context.packageManager.getLaunchIntentForPackage("org.telegram.messenger.web") // 这里如果intent为空,就说名没有安装要跳转的应用嘛if (intent != null) {// 这里跟Activity传递参数一样的嘛,不要担心怎么传递参数,还有接收参数也是跟Activity和Activity传参数一样context.startActivity(intent)} else {// 没有安装要跳转的app应用,提醒一下ToastUtils.showToast(context.resources.getString(R.string.Youhavenotinstalledthissoftwareyet))}

8.复制utils

package com.example.merchant.utilsimport android.content.ClipboardManager
import android.content.Context
import android.content.Context.CLIPBOARD_SERVICE
import com.example.merchant.R/*** @Author : CaoLiulang* @Time : 2023/9/27 14:11* @Description :复制工具类*/
class CopyUtils {companion object {fun copy(messsage: String?, context: Context) {var cm = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManagercm!!.text = messsage // 复制}fun copyts(messsage: String?, context: Context) {var cm = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManagercm!!.text = messsage // 复制ToastUtils.showToast(context.getString(R.string.Copysuccessfully))}}
}

总结

实现很简单,就两步几行代码完美收工,喜欢点个赞,不喜欢点个关注谢谢!

相关文章:

Android之App跳转其他软件

文章目录 前言一、效果图二、实现步骤1.弹框xml(自己替换图标)2.弹框utils3.两个弹框动画4.封装方便调用5.调用6.长按事件方法7.跳转步骤8.复制utils 总结 前言 最近遇到一个需求&#xff0c;就是App内大面积需要长按复制并跳转指定App&#xff0c;没办法&#xff0c;只能埋头…...

【Element UI】解决 el-dialog 弹框组件设置 custom-class 样式不生效问题

文章目录 问题描述解决方法 问题描述 <template><el-dialog class"myDialog" v-model"show" title"弹窗" custom-class"customDialog"><div>弹窗内容</div></el-dialog> </template> <script…...

前端菜鸟浅谈Web前端开发技术

Web前端开发技术按照过程遵循了由容易到困难&#xff0c;这就请求Web前端开发工作技术员方面要熟练学习基础的Web开发技术&#xff0c;关于网站性能的美化、SEO以及基础的关于服务器端方面的知识&#xff1b;另一方面还对开发人员有具体要求&#xff0c;比如能够熟练且灵敏的使…...

Springboot项目log4j与logback的Jar包冲突问题

异常信息关键词&#xff1a; SLF4J: Class path contains multiple SLF4J bindings. ERROR in ch.qos.logback.core.joran.spi.Interpreter24:14 - no applicable action for [properties], current ElementPath is [[configuration][properties]] 详细异常信息&#xff1a…...

光伏并网逆变器低电压穿越技术研究(Simulink仿真)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…...

命令模式,命令 Command 类对象的设计(设计模式与开发实践 P9)

文章目录 命令举例撤销C# 例子 命令 命令模式 Command 指的是一个 执行某些特定事情的指令 应用场景&#xff1a;有时需要向某些对象发送请求&#xff0c;但并不知道请求的接受者是谁&#xff0c;也不知道被请求的操作是什么。这时候命令模式就负责使发送者和接受者之间解耦 …...

jira 浏览器插件在问题列表页快速编辑问题标题

jira-issueTable-quicker 这是一个可以帮助我们在问题表格页快速编辑问题的浏览器插件 github 地址 功能介绍 jira 不可否认是一个可以帮助有效提高工作效率的工具&#xff0c;但是我们在使用 jira 时使用问题表格可以让我们看到跟多的内容而不用关注细节&#xff0c;但是目…...

2020架构真题(四十六)

、以下关于操作系统微内核架构特征的说法&#xff0c;不正确的是&#xff08;&#xff09;。 微内核的系统结构清晰&#xff0c;利于协作开发微内核代码量少&#xff0c;系统具有良好的可移植性微内核有良好的的伸缩性和扩展性微内核功能代码可以互相调用&#xff0c;性能很高…...

软件工程与计算总结(五)软件需求基础

本帖介绍软件需求涉及的诸多基本概念&#xff0c;通过对这些概念的阐述&#xff0c;剖析软件需求的来源、层次、类别、作用等重要知识~ 目录 ​编辑 一.引言 二.需求工程基础 1.简介 2.活动 3.需求获取 4.需求分析 5.需求规格说明 6.需求验证 7.需求管理 三.需求基…...

数学建模预测模型MATLAB代码大合集及皮尔逊相关性分析(无需调试、开源)

已知2010-2020数据&#xff0c;预测2021-2060数据 一、Logistic预测人口 %%logistic预测2021-2060年结果 clear;clc; X[7869.34, 8022.99, 8119.81, 8192.44, 8281.09, 8315.11, 8381.47, 8423.50, 8446.19, 8469.09, 8477.26]; nlength(X)-1; for t1:nZ(t)(X(t1)-X(t))/X(t1…...

泛型擦除是什么?

泛型擦除的主要特点包括&#xff1a; 编译时类型检查&#xff1a;在编写泛型代码时&#xff0c;编译器会对泛型类型参数进行类型检查&#xff0c;以确保类型安全。这意味着在编译时会捕获许多类型错误&#xff0c;避免了运行时类型错误。因为泛型其实只是在编译器中实现的而虚拟…...

阿里云轻量应用服务器有月流量限制吗?

阿里云轻量应用服务器限制流量吗&#xff1f;部分限制&#xff0c;2核2G3M和2核4G4M这两款轻量应用服务器不限制月流量&#xff0c;其他的轻量服务器套餐有月流量限制。 腾讯云轻量应用服务器价格便宜&#xff0c;活动页面&#xff1a;aliyunbaike.com/go/tencent 细心的同学看…...

mysql面试题25:数据库自增主键可能会遇到什么问题?应该怎么解决呢?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:数据库自增主键可能会遇到什么问题? 数据库自增主键可能遇到的问题: 冲突问题:自增主键是通过自动递增生成的唯一标识符,但在某些情况下可能会…...

学习css 伪类:has

学习抖音&#xff1a; 渡一前端提薪课 首先我们看下:has(selector)是什么 匹配包含&#xff08;相对于 selector 的 :scope&#xff09;指定选择器的元素。可以认为 selector 的前面有一个看不见的 :scope 伪类。它的强大之处是&#xff0c;可以实现父选择器和前面兄弟选择器…...

矩阵的相似性度量的常用方法

矩阵的相似性度量的常用方法 1&#xff0c;欧氏距离 欧式距离是最易于理解的一种距离计算方法&#xff0c;源自欧式空间中两点间的距离公式。 (1)二维平面上的点 a ( x 1 , y 1 ) a(x_1,y_1) a(x1​,y1​)和点 b ( x 2 , y 2 ) b(x_2,y_2) b(x2​,y2​)的欧式距离为 d ( x …...

Java之TCP,UDP综合小练习一

4. 综合练习 练习一&#xff1a;多发多收 需求&#xff1a; 客户端&#xff1a;多次发送数据 服务器&#xff1a;接收多次接收数据&#xff0c;并打印 代码示例&#xff1a; public class Client {public static void main(String[] args) throws IOException {//客户端&…...

Docker 日志管理 - ELK

Author&#xff1a;rab 目录 前言一、Docker 日志驱动二、ELK 套件部署三、Docker 容器日志采集3.1 部署 Filebeat3.2 配置 Filebeat3.3 验证采集数据3.4 Kibana 数据展示3.4.1 创建索引模式3.4.2 Kibana 查看日志 总结 前言 如何查看/管理 Docker 运行容器的日志&#xff1f;…...

windows系统下利用python对指定文件夹下面的所有文件的创建时间进行修改

windows系统下利用python对指定文件夹下面的所有文件的创建时间进行修改 不知道其他的朋友们有没有这个需求哈&#xff0c;反正咱家是有这个需求 需求1、当前有大量的文件需要更改文件生成的时间&#xff0c;因为不可告知的原因&#xff0c;当前的文件创建时间是不能满足使用的…...

线性表的链式表示——单链表;头插,尾插,按值查找,按序号查找,插入,删除;

#include <iostream> #include <algorithm>//fill() #define InitSize 5using namespace std;/*线性表&#xff1a;链式表示——单链表&#xff1b;头插&#xff0c;尾插&#xff0c;按值查找&#xff0c;按序号查找&#xff0c;插入&#xff0c;删除*/ typedef st…...

【Spring Cloud系统】- Zookeer特性与使用场景

【Spring Cloud系统】- Zookeer特性与使用场景 一、概述 Zookeeper是一个分布式服务框架&#xff0c;是Apache Hadoop的一个子项目&#xff0c;它主要是用来解决分布式应用中经常遇到的一些数据管理问题。如&#xff1a;统一命名服务、状态同步服务、集群管理、分布式应用配置…...

VB.net复制Ntag213卡写入UID

本示例使用的发卡器&#xff1a;https://item.taobao.com/item.htm?ftt&id615391857885 一、读取旧Ntag卡的UID和数据 Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click轻松读卡技术支持:网站:Dim i, j As IntegerDim cardidhex, …...

《Playwright:微软的自动化测试工具详解》

Playwright 简介:声明内容来自网络&#xff0c;将内容拼接整理出来的文档 Playwright 是微软开发的自动化测试工具&#xff0c;支持 Chrome、Firefox、Safari 等主流浏览器&#xff0c;提供多语言 API&#xff08;Python、JavaScript、Java、.NET&#xff09;。它的特点包括&a…...

解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错

出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上&#xff0c;所以报错&#xff0c;到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本&#xff0c;cu、torch、cp 的版本一定要对…...

音视频——I2S 协议详解

I2S 协议详解 I2S (Inter-IC Sound) 协议是一种串行总线协议&#xff0c;专门用于在数字音频设备之间传输数字音频数据。它由飞利浦&#xff08;Philips&#xff09;公司开发&#xff0c;以其简单、高效和广泛的兼容性而闻名。 1. 信号线 I2S 协议通常使用三根或四根信号线&a…...

Python竞赛环境搭建全攻略

Python环境搭建竞赛技术文章大纲 竞赛背景与意义 竞赛的目的与价值Python在竞赛中的应用场景环境搭建对竞赛效率的影响 竞赛环境需求分析 常见竞赛类型&#xff08;算法、数据分析、机器学习等&#xff09;不同竞赛对Python版本及库的要求硬件与操作系统的兼容性问题 Pyth…...

自然语言处理——文本分类

文本分类 传统机器学习方法文本表示向量空间模型 特征选择文档频率互信息信息增益&#xff08;IG&#xff09; 分类器设计贝叶斯理论&#xff1a;线性判别函数 文本分类性能评估P-R曲线ROC曲线 将文本文档或句子分类为预定义的类或类别&#xff0c; 有单标签多类别文本分类和多…...

Unity VR/MR开发-VR开发与传统3D开发的差异

视频讲解链接&#xff1a;【XR马斯维】VR/MR开发与传统3D开发的差异【UnityVR/MR开发教程--入门】_哔哩哔哩_bilibili...

DAY 26 函数专题1

函数定义与参数知识点回顾&#xff1a;1. 函数的定义2. 变量作用域&#xff1a;局部变量和全局变量3. 函数的参数类型&#xff1a;位置参数、默认参数、不定参数4. 传递参数的手段&#xff1a;关键词参数5 题目1&#xff1a;计算圆的面积 任务&#xff1a; 编写一…...

前端开发者常用网站

Can I use网站&#xff1a;一个查询网页技术兼容性的网站 一个查询网页技术兼容性的网站Can I use&#xff1a;Can I use... Support tables for HTML5, CSS3, etc (查询浏览器对HTML5的支持情况) 权威网站&#xff1a;MDN JavaScript权威网站&#xff1a;JavaScript | MDN...

聚六亚甲基单胍盐酸盐市场深度解析:现状、挑战与机遇

根据 QYResearch 发布的市场报告显示&#xff0c;全球市场规模预计在 2031 年达到 9848 万美元&#xff0c;2025 - 2031 年期间年复合增长率&#xff08;CAGR&#xff09;为 3.7%。在竞争格局上&#xff0c;市场集中度较高&#xff0c;2024 年全球前十强厂商占据约 74.0% 的市场…...