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"/>
    <data
        android: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 {
        //测试商品url
        val intent = Intent()
        intent.action = "Android.intent.action.VIEW"
        val uri = Uri.parse(url) // 商品地址
        intent.data = uri
        intent.setClassName(
            "com.taobao.taobao",
            "com.taobao.tao.detail.activity.DetailActivity"
        )
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        activity.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 {
        //手机已安装,返回true
        mContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        //手机未安装,跳转到应用商店下载,并返回false
        Uri uri = Uri.parse("market://details?id="+packageName);
        Intent it = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(it);
        return false;
    }
}

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值