Android 打开另一个APP,H5打开APP方法,打开淘宝、京东、天猫、拼多多。需求、商品详情或优惠券页面

1、在待打开的APP注册可被外APP调用的activity

<activity android:name=".TwoActivity"><intent-filter ><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT"/><data android:scheme="test"android:host="com.example.mvvmtest"android:path="/home" /></intent-filter>
</activity>

注:host是包名

2、任意APP打开已注册的开放的activity

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("test://com.example.mvvmtest/home"));
intent.putExtra("name","aacc44");
startActivity(intent);

H5打开APP

<intent-filter><category android:name="android.intent.category.DEFAULT"/><action android:name="android.intent.action.VIEW"/><category android:name="android.intent.category.BROWSABLE"/><dataandroid:scheme="dogness"android:host="rice"android:path="/device"/>
</intent-filter>

dongness://rice/device 

 dongness://rice/device?sn=365622952860844032

Uri uri  = getIntent().getData();
if (uri !=null){xiexunss = uri.getQueryParameter("dognesscode");LgqLogPlus.d("浏览器返回==== "+xiexunss);SharedPreUtil.putString("liulanqidp",xiexunss);
}

APP跳转到淘宝商品详情和优惠券页面demo

/*** 跳转至商品详情** @param activity Activity* @param url      商品详情*/
fun gotoGoodsDetail(activity: Activity, url: String?) {try {//测试商品urlval intent = Intent()intent.action = "Android.intent.action.VIEW"val uri = Uri.parse(url) // 商品地址intent.data = uriintent.setClassName("com.taobao.taobao","com.taobao.tao.detail.activity.DetailActivity")intent.flags = Intent.FLAG_ACTIVITY_NEW_TASKactivity.startActivity(intent)} catch (e: Exception) {e.printStackTrace()}
}

京东,天猫,淘宝,拼多多

    /*** 跳转京东详情页*/public void openJD2(String id) {if (checkPackage("com.jingdong.app.mall")) {
//            String url = "https://item.jd.com/231023.html";//这是京东商品详情页
//            String id = "100038821904";//需要提取商品id,添加到下面url,不能单独将商品详情页作为url传入String url = "openapp.jdmobile://virtual?params=%7B%22sourceValue%22:%220_productDetail_97%22,%22des%22:%22productDetail%22,%22skuId%22:%22"+id+"%22,%22category%22:%22jump%22,%22sourceType%22:%22PCUBE_CHANNEL%22%7D";Intent intent = new Intent();intent.setAction("android.intent.action.VIEW");Uri uri = Uri.parse(url);intent.setData(uri);
//            intent.setClassName("com.jingdong.app.mall","com.jd.lib.productdetail.ProductDetailActivity");//不需要startActivity(intent);}}

 

     if (appChannel!=null&&appChannel.equals("JD")){if (checkPackage("com.jingdong.app.mall")) {openJD2("100038821904");
//                                    openJD2(url);return;}}if (appChannel!=null&&appChannel.equals("TMAO")){if (checkPackage("com.tmall.wireless")) {gotoShop(getActivity(), url);
//                                    gotoShop(getActivity(), "tmall://page.tm/shop?shopId=185441148");return;}}if (appChannel!=null&&appChannel.equals("TBAO")){if (checkPackage("com.taobao.taobao")) {gotoShop(getActivity(), url);
//                                    gotoShop(getActivity(), "taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=185441148");return;}}if (appChannel!=null&&appChannel.equals("PDD")){if (checkPackage("com.xunmeng.pinduoduo")) {
//                                    String content = "pinduoduo://com.xunmeng.pinduoduo/duo_coupon_landing.html?goods_id=329990619550";String content = url;Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(content));startActivity(intent);return;}}

 

/*** 跳转至商铺** @param activity Activity* @param url      商铺地址*/
public static void gotoShop(Activity activity, String url) {try {Intent intent = new Intent();intent.setAction("android.intent.action.VIEW");intent.setData(Uri.parse(url));activity.startActivity(intent);} catch (Exception e) {e.printStackTrace();}
}

 

/*** 检测该包名所对应的应用是否存在** @param packageName* @return*/
public boolean checkPackage(String packageName) {if (packageName == null || "".equals(packageName)) return false;try {//手机已安装,返回truemContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);return true;} catch (PackageManager.NameNotFoundException e) {//手机未安装,跳转到应用商店下载,并返回falseUri uri = Uri.parse("market://details?id="+packageName);Intent it = new Intent(Intent.ACTION_VIEW, uri);startActivity(it);return false;}
}

 

demo连接:android开发,APP跳转到淘宝商品详情,优惠券领取页面-Android文档类资源-CSDN下载

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414436.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android 获取短信验证码,自动填充

1、申请权限 <uses-permission android:name"android.permission.RECEIVE_SMS" /> <uses-permission android:name"android.permission.READ_SMS" /> API>23动态申请权限 private static final String[] authBaseArr {//申请类型Manife…

网络请求之优化参数添加工具类自定义Map类

导入依赖&#xff1a; implementation com.squareup.okhttp3:okhttp:3.4.1 调用方法&#xff1a; File file new File("");HttpParams params new HttpParams(); params.put("mobile", "22"); params.put("password", 33); params.…

android studio 导入依赖报错——Could not find com.xxx,(# fields: 66338 > 65536)

替换项目build.gradle即可 buildscript {repositories {maven{url https://maven.aliyun.com/repository/google}maven{url https://maven.aliyun.com/repository/jcenter} // maven{url https://maven.aliyun.com/nexus/content/groups/public}maven { url "http…

spring-boot-starter-parent

一、你的项目 pom.xml 中有这段代码吗 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.5.RELEASE</version><relativePath/> </parent>idea &…

java学习--基础知识阶段性总结--网络编程

网络编程&#xff1a; 端口&#xff1a; 物理端口&#xff1a; 逻辑端口&#xff1a;用于标识进程的逻辑地址&#xff0c;不同进程的标识&#xff1b;有效端口&#xff1a;0~65535&#xff0c;其中0~1024系统使用或保留端口。 java 中ip对象&#xff1a;InetAddress. import ja…

android 加载显示富文本——TextView显示富文本和WebView显示富文本,WebView显示图片适配屏幕宽度

"connectDeviceLedStatus_dcq":"请先确认设备指示灯为 <strong><font color\"#088A01\">绿灯闪烁</font></strong> 状态。", tv_dev_one_tip1.setText(Html.fromHtml(LangComm.getString("feeder_ble_bind_guide_t…

项目集成Spring Security

前言 之前写的 涂涂影院管理系统 这个 demo 是基于 shiro 来鉴权的&#xff0c;项目前后端分离后&#xff0c;显然集成 Spring Security 更加方便一些&#xff0c;毕竟&#xff0c;都用 Spring 了&#xff0c;权限管理当然 Spring Security. 花了半天时间整理的笔记&#xff0…

android 使用AIDL实现进程间通讯

一、创建服务端 1、首先创建AIDL文件 2、创建service&#xff0c;绑定AIDL接口 3、配置service <service android:name".AidlService"android:enabled"true"android:exported"true"><intent-filter android:priority"1000"&…

大数据入门第二十天——scala入门(二)scala基础02

一、 类、对象、继承、特质 1.类 Scala的类与Java、C的类比起来更简洁 定义&#xff1a; package com.jiangbei //在Scala中&#xff0c;类并不用声明为public。 //Scala源文件中可以包含多个类&#xff0c;所有这些类都具有公有可见性。 class Person {// 定义一个不可变的val…

SpringSecurity 整合 JWT

项目集成Spring Security&#xff08;一&#xff09; 在上一篇基础上继续集成 JWT &#xff0c;实现用户身份验证。 前言 前后端分离项目中&#xff0c;如果直接把 API 接口对外开放&#xff0c;我们知道这样风险是很大的&#xff0c;所以在上一篇中我们引入了 Spring Securit…

MySQL 使用自增ID主键和UUID 作为主键的优劣比较详细过程(从百万到千万表记录测试)...

Reference: https://blog.csdn.net/mchdba/article/details/52336203 一个开发同事做了一个框架&#xff0c;里面主键是uuid&#xff0c;我跟他建议说mysql不要用uuid用自增主键&#xff0c;自增主键效率高&#xff0c;他说不一定高&#xff0c;我说innodb的索引特性导致了自增…

String 字符串去除特殊字符和空格,正则表达式使用,%1$s,摄氏度和华氏度相互转换

*华氏度转摄氏度 ℃ (οF - 32) / 1.8 摄氏度转华氏度 F (9/5)*C 32 摄氏度转华氏度 fahrenheit (9/5.0) * wd 32; fahrenheit2 (9/5.0) * wd2 32; int hs (int) fahrenheit; 华氏度转摄氏度 degree (fahrenheit - 32)*5/9; 特殊字符 String tt "sdfdf{fwe }…