A apk 拉起 B apk



ComponentName componetName = new ComponentName("com.chinamobile.mcloud",
        "com.chinamobile.mcloud.client.service.ActivatorService");
try {
    Intent intent = new Intent();
    intent.setComponent(componetName);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("packageName",getPackageName());//调用方应用包名
    startService(intent);
} catch (Exception e) {
    e.printStackTrace();
}

 

 

package com.liangMei.hjlb.moudle.my;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.liangMei.hjlb.R;
import com.liangMei.hjlb.framework.app.BaseActivity;

import java.io.File;

/**
 * @Example
 * @Auth : LiBo on 2019/2/25 0025
 * @Describe :
 */
public class MainActivity     extends BaseActivity {
    public static Intent getLauncherIntent(Activity activity) {
        Intent intent = new Intent(activity, MainActivity.class);
        return intent;
    }

    //---京东和淘宝的商铺及商品ID
    private String TaoBaoShopId = "131259851";   //--耐凡眼镜店
    private String JDShopId = "1000004123";     //--京东小米官方旗舰店
    private String TaoBaoGoodsId = "525249416835";  //--时尚潮流复古学生...眼镜框
    private String JDGoodsId = "4099139";       //--小米6详情页

    //--1.打开京东或淘宝的店铺
    private String taobaoAppStr_shop = "taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=" + TaoBaoShopId + "";
    private String taobaoWebStr_shop = "https://shop.m.taobao.com/shop/shop_index.htm?shop_id=" + TaoBaoShopId + "";
    private String jdAppStr_shop = "openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"jshopMain\",\"shopId\":\"" + JDShopId + "\",\"sourceType\":\"M_sourceFrom\",\"sourceValue\":\"dp\"}";
    private String jdWebStr_shop = "http://shop.m.jd.com/?shopId=" + JDShopId + "";

    //--2.打开京东或淘宝的商品详情页
    private String taobaoAppStr_goods = "taobao://item.taobao.com/item.htm?id=" + TaoBaoGoodsId + "";
    private String taobaoWebStr_goods = "https://item.taobao.com/item.htm?id=" + TaoBaoGoodsId + "";
    private String jdAppStr_goods = "openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"productDetail\",\"skuId\":\"" + JDGoodsId + "\",\"sourceType\":\"JSHOP_SOURCE_TYPE\",\"sourceValue\":\"JSHOP_SOURCE_VALUE\"}";
    private String jdWebStr_goods = "https://item.m.jd.com/product/" + JDGoodsId + ".html";

    //--3.京东和淘宝的包名
    private String mJDMall = "com.jingdong.app.mall";
    private String mTaoBao = "com.taobao.taobao";

    /**
     * 1. 可以从第三方应用跳转到QQ界面,并可以进入指定的QQ号码的聊天界面(可以是陌生人QQ号).
     * String url="mqqwpa://im/chat?chat_type=wpa&uin=1642084864";
     * startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
     * //指定的QQ号只需要修改uin后的值即可。
     */


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainq);
        initView();
    }

    @Override
    protected void initLogics() {

    }

    private void initView() {
        findViewById(R.id.jump_to_jd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //---jd
                if (isInstallByread(mJDMall)) {
                    Toast.makeText(MainActivity.this, "京东已经安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(jdAppStr_shop));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    Toast.makeText(MainActivity.this, "京东没有安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(jdWebStr_shop));
                    startActivity(intent);
//                    loadApp(mJDMall);
                }
            }
        });

        findViewById(R.id.jump_to_taobao).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //---taobao
                if (isInstallByread(mTaoBao)) {
                    Toast.makeText(MainActivity.this, "淘宝已经安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(taobaoAppStr_shop));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    Toast.makeText(MainActivity.this, "淘宝没有安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(taobaoWebStr_shop));
                    startActivity(intent);
//                    loadApp(mTaoBao);
                }
            }
        });

        findViewById(R.id.jump_to_jd_goods).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //---jd
                if (isInstallByread(mJDMall)) {
                    Toast.makeText(MainActivity.this, "京东已经安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(jdAppStr_goods));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    Toast.makeText(MainActivity.this, "京东没有安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(jdWebStr_goods));
                    startActivity(intent);
//                    loadApp(mJDMall);
                }
            }
        });

        findViewById(R.id.jump_to_taobao_goods).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//---taobao
                if (isInstallByread(mTaoBao)) {
                    Toast.makeText(MainActivity.this, "淘宝已经安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(taobaoAppStr_goods));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    Toast.makeText(MainActivity.this, "淘宝没有安装", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(taobaoWebStr_goods));
                    startActivity(intent);
//                    loadApp(mTaoBao);
                }
            }
        });

    }

    /**
     * 判断是否安装目标应用
     *
     * @param packageName 目标应用安装后的包名
     * @return 是否已安装目标应用
     */
    private boolean isInstallByread(String packageName) {
        return new File("/data/data/" + packageName).exists();
    }

    /**
     * 启动目标应用
     *
     * @param packageName 目标应用安装后的包名
     */
    private void launchApp(String packageName) {
        PackageManager packageManager = this.getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage(packageName);
        startActivity(intent);
    }

    /**
     * 下载目标应用
     *
     * @param packageName 目标应用安装后的包名
     */
    private void loadApp(String packageName) {
        Uri uri = Uri.parse("market://details?id=" + packageName);//id后面接包名
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }
}

 

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    android:gravity="center"
    android:background="@color/whitesmoke"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/jump_to_jd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/mdp13"
        android:layout_marginTop="@dimen/mdp45"
        android:layout_marginRight="@dimen/mdp13"
        android:background="@drawable/selector_btn_next"
        android:text="退出"
        android:textColor="@drawable/selector_btn_next_tc" />

    <Button
        android:id="@+id/jump_to_taobao"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/mdp13"
        android:layout_marginTop="@dimen/mdp45"
        android:layout_marginRight="@dimen/mdp13"
        android:background="@drawable/selector_btn_next"
        android:text="退出"
        android:textColor="@drawable/selector_btn_next_tc" />


    <Button
        android:id="@+id/jump_to_jd_goods"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/mdp13"
        android:layout_marginTop="@dimen/mdp45"
        android:layout_marginRight="@dimen/mdp13"
        android:background="@drawable/selector_btn_next"
        android:text="退出"
        android:textColor="@drawable/selector_btn_next_tc" />

    <Button
        android:id="@+id/jump_to_taobao_goods"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/mdp13"
        android:layout_marginTop="@dimen/mdp45"
        android:layout_marginRight="@dimen/mdp13"
        android:background="@drawable/selector_btn_next"
        android:text="退出"
        android:textColor="@drawable/selector_btn_next_tc" />




 
</LinearLayout>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值