当前位置: 首页 > 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;统一命名服务、状态同步服务、集群管理、分布式应用配置…...

业务系统对接大模型的基础方案:架构设计与关键步骤

业务系统对接大模型&#xff1a;架构设计与关键步骤 在当今数字化转型的浪潮中&#xff0c;大语言模型&#xff08;LLM&#xff09;已成为企业提升业务效率和创新能力的关键技术之一。将大模型集成到业务系统中&#xff0c;不仅可以优化用户体验&#xff0c;还能为业务决策提供…...

XCTF-web-easyupload

试了试php&#xff0c;php7&#xff0c;pht&#xff0c;phtml等&#xff0c;都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接&#xff0c;得到flag...

C++_核心编程_多态案例二-制作饮品

#include <iostream> #include <string> using namespace std;/*制作饮品的大致流程为&#xff1a;煮水 - 冲泡 - 倒入杯中 - 加入辅料 利用多态技术实现本案例&#xff0c;提供抽象制作饮品基类&#xff0c;提供子类制作咖啡和茶叶*//*基类*/ class AbstractDr…...

P3 QT项目----记事本(3.8)

3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...

【JavaSE】绘图与事件入门学习笔记

-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角&#xff0c;以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向&#xff0c;距离坐标原点x个像素;第二个是y坐标&#xff0c;表示当前位置为垂直方向&#xff0c;距离坐标原点y个像素。 坐标体系-像素 …...

全面解析各类VPN技术:GRE、IPsec、L2TP、SSL与MPLS VPN对比

目录 引言 VPN技术概述 GRE VPN 3.1 GRE封装结构 3.2 GRE的应用场景 GRE over IPsec 4.1 GRE over IPsec封装结构 4.2 为什么使用GRE over IPsec&#xff1f; IPsec VPN 5.1 IPsec传输模式&#xff08;Transport Mode&#xff09; 5.2 IPsec隧道模式&#xff08;Tunne…...

git: early EOF

macOS报错&#xff1a; Initialized empty Git repository in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/ remote: Enumerating objects: 2691797, done. remote: Counting objects: 100% (1760/1760), done. remote: Compressing objects: 100% (636/636…...

智能职业发展系统:AI驱动的职业规划平台技术解析

智能职业发展系统&#xff1a;AI驱动的职业规划平台技术解析 引言&#xff1a;数字时代的职业革命 在当今瞬息万变的就业市场中&#xff0c;传统的职业规划方法已无法满足个人和企业的需求。据统计&#xff0c;全球每年有超过2亿人面临职业转型困境&#xff0c;而企业也因此遭…...

深入浅出WebGL:在浏览器中解锁3D世界的魔法钥匙

WebGL&#xff1a;在浏览器中解锁3D世界的魔法钥匙 引言&#xff1a;网页的边界正在消失 在数字化浪潮的推动下&#xff0c;网页早已不再是静态信息的展示窗口。如今&#xff0c;我们可以在浏览器中体验逼真的3D游戏、交互式数据可视化、虚拟实验室&#xff0c;甚至沉浸式的V…...

【Ftrace 专栏】Ftrace 参考博文

ftrace、perf、bcc、bpftrace、ply、simple_perf的使用Ftrace 基本用法Linux 利用 ftrace 分析内核调用如何利用ftrace精确跟踪特定进程调度信息使用 ftrace 进行追踪延迟Linux-培训笔记-ftracehttps://www.kernel.org/doc/html/v4.18/trace/events.htmlhttps://blog.csdn.net/…...